Guest User

Untitled

a guest
Sep 9th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.42 KB | None | 0 0
  1. import timeit
  2.  
  3. num = 10000
  4. t1 = timeit.Timer('testfunc(1)', 'def testfunc(x): return 5+x;')
  5. t2 = timeit.Timer('testlambda(1)', 'testlambda = lambda x: x+5;')
  6.  
  7. time1 = t1.timeit(number=num)
  8. time2 = t2.timeit(number=num)
  9.  
  10. print 'simple function:',time1/num
  11. print 'simple lambda:',time2/num
  12.  
  13. '''
  14. squishy@EXCALIBUR ~/Documents $ python funcvlambda.py
  15. simple function: 2.92284110007e-07
  16. simple lambda: 2.90683115584e-07
  17. '''
Add Comment
Please, Sign In to add comment