Skip to content

Instantly share code, notes, and snippets.

@rdrewd
Created November 26, 2013 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdrewd/7654590 to your computer and use it in GitHub Desktop.
Save rdrewd/7654590 to your computer and use it in GitHub Desktop.
My "main" routine for Project Euler. Runs that program specified by arg1, times the execution and prints the answer and timing The timer is rather too coarse and the details (real time vs. CPU time) differ from Linux to WIndows.
from time import clock
if __name__ == "__main__":
import sys
print "args=", sys.argv
x="from " + sys.argv[1] + " import main"
print x
exec x
tstart=clock()*1000
answer=main()
tend=clock()*1000
print "answer=", answer
print "tstart=", "%e" % tstart, "tend=", "%e" % tend
print "runtime(CPU milliseconds)=", str(tend-tstart)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment