[pypy-svn] r29803 - pypy/dist/pypy/objspace/std/benchmark

fijal at codespeak.net fijal at codespeak.net
Sat Jul 8 13:06:50 CEST 2006


Author: fijal
Date: Sat Jul  8 13:06:45 2006
New Revision: 29803

Modified:
   pypy/dist/pypy/objspace/std/benchmark/bench_dict.py
Log:
Fixed

Modified: pypy/dist/pypy/objspace/std/benchmark/bench_dict.py
==============================================================================
--- pypy/dist/pypy/objspace/std/benchmark/bench_dict.py	(original)
+++ pypy/dist/pypy/objspace/std/benchmark/bench_dict.py	Sat Jul  8 13:06:45 2006
@@ -4,9 +4,18 @@
 
 import random, time
 
+def sample(population, num):
+    l = len(population)
+    retval = []
+    for i in xrange(num):
+        retval.append(population[random.randrange(l)])
+    return retval
+
+random.sample = sample
+
 def get_random_string(l):
     strings = 'qwertyuiopasdfghjklzxcvbm,./;QWERTYUIOPASDFGHJKLZXCVBNM!@#$%^&*()_+1234567890-='
-    random.sample(strings, l)
+    return str(random.sample(strings, l))
 
 def count_operation(name, function):
     print name
@@ -16,12 +25,12 @@
     print name, " takes: %f" % (tk - t0)
     return retval
 
-def bench_simple_dict(SIZE = 1000000):
+def bench_simple_dict(SIZE = 10000):
     keys = [get_random_string(20) for i in xrange(SIZE)]
     values = [random.random() for i in xrange(SIZE)]
-    
-    lookup_keys = random.sample(keys, 100000)
-    random_keys = [get_random_string(20) for i in xrange(100000)]
+
+    lookup_keys = random.sample(keys, 1000)
+    random_keys = [get_random_string(20) for i in xrange(1000)]
     
     test_d = count_operation("Creation", lambda : dict(zip(keys, values)))
 
@@ -34,6 +43,10 @@
     
     count_operation("Random key access", lambda : rand_keys(random_keys))
     count_operation("Existing key access", lambda : rand_keys(lookup_keys))
+    return test_d
 
 if __name__ == '__main__':
-    bench_simple_dict()
+    test_d = bench_simple_dict()
+    import sys
+    print sys.pypy_repr(test_d)
+    print sys.pypy_repr(test_d.iterkeys())



More information about the Pypy-commit mailing list