Skip to content

Instantly share code, notes, and snippets.

@reynir
Created October 30, 2013 17:19
Show Gist options
  • Save reynir/7236502 to your computer and use it in GitHub Desktop.
Save reynir/7236502 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import time
import sys
def fib(n):
return n if n <= 1 else fib(n-1) + fib(n-2)
def get_time():
return int(round(time.time() * 1000))
if __name__ == '__main__':
start = get_time()
N = int(sys.argv[1])
print("Fibonacci from 0 to %d:" % N)
for (i, fi) in map(lambda i: (i, fib(i)), range(N+1)):
print("%d: %d" % (i, fi))
stop = get_time()
print("time: %d ms" % (stop-start))
$ python2 fib.py 32 # Nothing happens for a few secs and then the fibonacci numbers are printed
$ python3 fib.py 32 # The fibonacci numbers are printed one by one with a greater and greater interval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment