Created
May 13, 2015 02:59
-
-
Save anonymous/1a1692be11b654c1ab06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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