Commits

Miki Tebeka committed a5936db

gcc

Comments (0)

Files changed (2)

+int main() {
+    return 0;
+}
 from os import environ, stat
 from stat import S_IXUSR
 from os.path import isfile, join
+from collections import namedtuple
 
 def which(name):
     for path in environ["PATH"].split(":"):
         if stat(full).st_mode & S_IXUSR:
             return full
 
+def with_args(command, **kw):
+    name, args = command[0], command[1:]
 
-def script(name, *command):
-    full = which(name)
+    full = name if ("/" in name) else which(name)
+
     assert full, "can't find %s" % name
 
-    command = list(command) if command else ["/dev/null"]
+    if (not args) and kw.get("arg"):
+        args = [kw["arg"]]
 
-    return { "name" : name.title(), "command" : [full] + command}
+    return [full] + list(args)
+
+Script = namedtuple("Script", ["name", "command"])
+
+def script(*args):
+    cmd = with_args(args, arg="/dev/null")
+
+    return Script(args[0].title(), cmd)
 
 scripts = [
     script("python"),
     script("mzscheme", "-e", ""),
 ]
 
+Program = namedtuple("Program", ["name", "compile", "run"])
+
+def program(compile, run):
+    name = compile[0]
+
+    return Program(compile[0].title(), with_args(compile), with_args(run))
+
+programs = [
+    program(["gcc", "-O3", "-o", "noop", "noop.c"],
+            ["./noop"])
+]
+
 def timeit(command):
     start = time()
     with open("/dev/null", "wb") as fo:
     runtimes = []
     for script in scripts:
         start = time()
-        runtimes.append((timeit(script["command"]), script["name"]))
+        runtimes.append((timeit(script.command), script.name))
+
+    for program in programs:
+        timeit(program.compile)
+        runtimes.append((timeit(program.run), program.name))
 
     maxlen = max((len(rt[1]) for rt in runtimes)) + 1
     runtimes.sort()