1#!/usr/bin/env python 2 3from __future__ import print_function 4 5class TimingScriptGenerator: 6 """Used to generate a bash script which will invoke the toy and time it""" 7 def __init__(self, scriptname, outputname): 8 self.shfile = open(scriptname, 'w') 9 self.timeFile = outputname 10 self.shfile.write("echo \"\" > %s\n" % self.timeFile) 11 12 def writeTimingCall(self, irname, callname): 13 """Echo some comments and invoke both versions of toy""" 14 rootname = irname 15 if '.' in irname: 16 rootname = irname[:irname.rfind('.')] 17 self.shfile.write("echo \"%s: Calls %s\" >> %s\n" % (callname, irname, self.timeFile)) 18 self.shfile.write("echo \"\" >> %s\n" % self.timeFile) 19 self.shfile.write("echo \"With MCJIT\" >> %s\n" % self.timeFile) 20 self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") 21 self.shfile.write(" -o %s -a " % self.timeFile) 22 self.shfile.write("./toy -suppress-prompts -use-mcjit=true -enable-lazy-compilation=true -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname, callname, rootname, rootname)) 23 self.shfile.write("echo \"\" >> %s\n" % self.timeFile) 24 self.shfile.write("echo \"With MCJIT again\" >> %s\n" % self.timeFile) 25 self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") 26 self.shfile.write(" -o %s -a " % self.timeFile) 27 self.shfile.write("./toy -suppress-prompts -use-mcjit=true -enable-lazy-compilation=true -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname, callname, rootname, rootname)) 28 self.shfile.write("echo \"\" >> %s\n" % self.timeFile) 29 self.shfile.write("echo \"With JIT\" >> %s\n" % self.timeFile) 30 self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") 31 self.shfile.write(" -o %s -a " % self.timeFile) 32 self.shfile.write("./toy -suppress-prompts -use-mcjit=false -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (irname, callname, rootname, rootname)) 33 self.shfile.write("echo \"\" >> %s\n" % self.timeFile) 34 self.shfile.write("echo \"\" >> %s\n" % self.timeFile) 35 36class LibScriptGenerator: 37 """Used to generate a bash script which will invoke the toy and time it""" 38 def __init__(self, filename): 39 self.shfile = open(filename, 'w') 40 41 def writeLibGenCall(self, libname, irname): 42 self.shfile.write("./toy -suppress-prompts -use-mcjit=false -dump-modules < %s 2> %s\n" % (libname, irname)) 43 44def splitScript(inputname, libGenScript, timingScript): 45 rootname = inputname[:-2] 46 libname = rootname + "-lib.k" 47 irname = rootname + "-lib.ir" 48 callname = rootname + "-call.k" 49 infile = open(inputname, "r") 50 libfile = open(libname, "w") 51 callfile = open(callname, "w") 52 print("Splitting %s into %s and %s" % (inputname, callname, libname)) 53 for line in infile: 54 if not line.startswith("#"): 55 if line.startswith("print"): 56 callfile.write(line) 57 else: 58 libfile.write(line) 59 libGenScript.writeLibGenCall(libname, irname) 60 timingScript.writeTimingCall(irname, callname) 61 62# Execution begins here 63libGenScript = LibScriptGenerator("make-libs.sh") 64timingScript = TimingScriptGenerator("time-lib.sh", "lib-timing.txt") 65 66script_list = ["test-5000-3-50-50.k", "test-5000-10-100-10.k", "test-5000-10-5-10.k", "test-5000-10-1-0.k", 67 "test-1000-3-10-50.k", "test-1000-10-100-10.k", "test-1000-10-5-10.k", "test-1000-10-1-0.k", 68 "test-200-3-2-50.k", "test-200-10-40-10.k", "test-200-10-2-10.k", "test-200-10-1-0.k"] 69 70for script in script_list: 71 splitScript(script, libGenScript, timingScript) 72print("All done!") 73