Skip to content

Instantly share code, notes, and snippets.

@keshavagrawal89
Created August 28, 2014 15:09
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 keshavagrawal89/aeb439130dfa12e1e58a to your computer and use it in GitHub Desktop.
Save keshavagrawal89/aeb439130dfa12e1e58a to your computer and use it in GitHub Desktop.
local rebinding fun ;)
__author__ = 'keshavagrawal'
import math
import timeit
def this_one_must_be_fast(sin=math.sin, cos=math.cos):
for i in xrange(10000):
sin(5)
cos(5)
def this_one_not_so_fast():
for i in xrange(10000):
math.sin(5)
math.cos(5)
print "Fast one: ", timeit.timeit(this_one_must_be_fast, number=10000)
print "Not so fast: ", timeit.timeit(this_one_not_so_fast, number=10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment