code_junkie

Python Decimal

Nov 11th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. from timeit import Timer
  2.  
  3. def run(val, the_class):
  4. test = the_class(1)
  5. for c in xrange(10000):
  6. d = the_class(val)
  7. d + test
  8. d - test
  9. d * test
  10. d / test
  11. d ** test
  12. str(d)
  13. abs(d)
  14.  
  15. if __name__ == "__main__":
  16. a = Timer("run(123.345, float)", "from decimal_benchmark import run")
  17. print "FLOAT", a.timeit(1)
  18. a = Timer("run('123.345', Decimal)", "from decimal_benchmark import run; from decimal import Decimal")
  19. print "DECIMAL", a.timeit(1)
  20.  
  21. FLOAT 0.040635041427
  22. DECIMAL 3.39666790146
Add Comment
Please, Sign In to add comment