Skip to content

Instantly share code, notes, and snippets.

@Fluxx
Created January 30, 2013 21:39
Show Gist options
  • Select an option

  • Save Fluxx/4677323 to your computer and use it in GitHub Desktop.

Select an option

Save Fluxx/4677323 to your computer and use it in GitHub Desktop.
import time
from contextlib import contextmanager
from decimal import Decimal
ITERATIONS = 500000
TRIALS = 10
makedecimal_lambda = lambda v: Decimal(str(v))
def makedecimal_func(v):
return Decimal(str(v))
@contextmanager
def timeit(label):
start = time.time()
yield
print '%s took %s' % (label, time.time() - start)
for i in range(TRIALS):
with timeit('lambda'):
map(makedecimal_lambda, range(ITERATIONS))
with timeit('func'):
map(makedecimal_func, range(ITERATIONS))
print '-' * 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment