Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2008 Doug Hellmann All rights reserved.
  5. #
  6. """
  7. """
  8.  
  9. __version__ = "$Id$"
  10. #end_pymotw_header
  11.  
  12. import timeit
  13.  
  14. iterations = 1000
  15.  
  16. def show_results(title, result, iterations):
  17. "Print results in terms of microseconds per pass and per item."
  18. per_pass = 1000000 * (result / iterations)
  19. print '%s:\t%.2f usec/pass' % (title, per_pass)
  20.  
  21.  
  22. adler32 = timeit.Timer(
  23. stmt="zlib.adler32(data)",
  24. setup="import zlib; data=open('lorem.txt','r').read() * 10",
  25. )
  26. show_results('Adler32, separate',
  27. adler32.timeit(iterations), iterations)
  28.  
  29. adler32_running = timeit.Timer(
  30. stmt="cksum = zlib.adler32(data, cksum)",
  31. setup="""import zlib
  32. data=open('lorem.txt','r').read() * 10
  33. cksum = zlib.adler32(data)""",
  34. )
  35. show_results('Adler32, running',
  36. adler32_running.timeit(iterations), iterations)
  37.  
  38. crc32 = timeit.Timer(
  39. stmt="zlib.crc32(data)",
  40. setup="import zlib; data=open('lorem.txt','r').read() * 10",
  41. )
  42. show_results('CRC-32, separate',
  43. crc32.timeit(iterations), iterations)
  44.  
  45. crc32_running = timeit.Timer(
  46. stmt="cksum = zlib.crc32(data, cksum)",
  47. setup="""import zlib
  48. data=open('lorem.txt','r').read() * 10
  49. cksum = zlib.crc32(data)""",
  50. )
  51. show_results('CRC-32, running',
  52. crc32_running.timeit(iterations), iterations)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement