Created
August 28, 2014 15:09
-
-
Save keshavagrawal89/aeb439130dfa12e1e58a to your computer and use it in GitHub Desktop.
local rebinding fun ;)
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
__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