Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from time import time
- def test_create():
- """
- Test performance of creating a new dictionary or clearing a dictionary.
- """
- adict = {}
- start = time()
- for i in range(range1):
- for xx in range(range2):
- adict['bobwasher%s' % xx] = {'t': 1234123, 'd': {'zxcv': 12903}}
- bdict = adict
- adict = {}
- stop = time()
- elapsed = float(stop) - float(start)
- print("Elapsed create: %.4f" % elapsed)
- start = time()
- for i in range(range1):
- for xx in range(range2):
- adict['bobwasher%s' % xx] = {'t': 1234123, 'd': {'zxcv': 12903}}
- bdict = adict
- adict.clear()
- stop = time()
- elapsed = float(stop) - float(start)
- print("Elapsed empty: %.4f" % elapsed)
- range1 = 40000
- range2 = 600
- test_create()
- # Results:
- # Elapsed create: 10.9880
- # Elapsed empty: 10.3509
Add Comment
Please, Sign In to add comment