diff options
author | hut <hut@lavabit.com> | 2009-11-27 10:49:48 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-11-27 10:49:48 +0100 |
commit | 9506fb8e79f2d04a1ab78039bacdbee7b22109b5 (patch) | |
tree | 3d5c682e9c5032a1c23be6a98c9d3d6e7c8224b5 /test4.py | |
parent | 5822dff7d91472bf2fc337c68f144e0ce1de09ae (diff) | |
download | ranger-9506fb8e79f2d04a1ab78039bacdbee7b22109b5.tar.gz |
more VROOM
Diffstat (limited to 'test4.py')
-rw-r--r-- | test4.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test4.py b/test4.py new file mode 100644 index 00000000..b2390a03 --- /dev/null +++ b/test4.py @@ -0,0 +1,36 @@ +import random, time + +class DelValue(): + def a(d): + return dict((k, v) for k, v in d.items() if v is not 0) + + def b(d): + for k, v in d.copy().items(): + if v == 0: del d[k] + return d + + def c(d): + for k in tuple(d.keys()): + if d[k] == 0: del d[k] + return d + + def d(d): + for k, v in tuple(d.items()): + if v == 0: del d[k] + return d + + +basedict = {} +for i in range(200): + basedict[i] = random.randint(0, 1) + +expected = DelValue.a(basedict.copy()) + +for algo in ['a', 'b', 'c', 'd']: + copy = basedict.copy() + t = time.time() + for i in range(100): + assert DelValue.__dict__[algo](copy) == expected + print("algorithm %s: %f" % (algo, time.time() - t)) + +# c it is, although b is faster with smaller dictionaries |