Guest User

Untitled

a guest
Jan 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import random
  2. from time import time
  3. def test_create():
  4. """
  5. Test performance of creating a new dictionary or clearing a dictionary.
  6. """
  7. adict = {}
  8. start = time()
  9. for i in range(range1):
  10. for xx in range(range2):
  11. adict['bobwasher%s' % xx] = {'t': 1234123, 'd': {'zxcv': 12903}}
  12. bdict = adict
  13. adict = {}
  14. stop = time()
  15. elapsed = float(stop) - float(start)
  16. print("Elapsed create: %.4f" % elapsed)
  17. start = time()
  18. for i in range(range1):
  19. for xx in range(range2):
  20. adict['bobwasher%s' % xx] = {'t': 1234123, 'd': {'zxcv': 12903}}
  21. bdict = adict
  22. adict.clear()
  23. stop = time()
  24. elapsed = float(stop) - float(start)
  25. print("Elapsed empty: %.4f" % elapsed)
  26.  
  27. range1 = 40000
  28. range2 = 600
  29.  
  30. test_create()
  31.  
  32. # Results:
  33. # Elapsed create: 10.9880
  34. # Elapsed empty: 10.3509
Add Comment
Please, Sign In to add comment