Skip to content

Instantly share code, notes, and snippets.

Created May 13, 2015 02:59
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 anonymous/1a1692be11b654c1ab06 to your computer and use it in GitHub Desktop.
Save anonymous/1a1692be11b654c1ab06 to your computer and use it in GitHub Desktop.
import datetime
def add(x): return x*100 + 1
def count(x): return x + 1
def f1(a,b):
if b==99:
return a
else:
return f1(add(a),count(b))
def f2():
a=0
for x in xrange(1,100):
a=a*100+1
return a
def main():
starttime = datetime.datetime.now()
print f1(1,1)
endtime = datetime.datetime.now()
print (endtime - starttime).microseconds
starttime = datetime.datetime.now()
print f2()
endtime = datetime.datetime.now()
print (endtime - starttime).microseconds
starttime = datetime.datetime.now()
print bin(sum(1 << (x << 1) for x in range(99))).lstrip('0b')
endtime = datetime.datetime.now()
print (endtime - starttime).microseconds
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment