]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
directories: update the directory benchmarks to exercise the unpack-and-repack functi...
authorZooko O'Whielacronx <zooko@zooko.com>
Sun, 5 Jul 2009 16:29:53 +0000 (09:29 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Sun, 5 Jul 2009 16:29:53 +0000 (09:29 -0700)
src/allmydata/test/bench_dirnode.py

index ae48a5500746c4754a53b18cac384d7cc3c71e53..e72fbbc0c6e7a72fc2f65b5bea766725efc8a25b 100644 (file)
@@ -1,4 +1,4 @@
-import os, random
+import hotshot.stats, os, random
 
 from pyutil import benchutil, randutil # http://allmydata.org/trac/pyutil
 
@@ -85,17 +85,23 @@ def pack(N):
 def unpack(N):
     return testdirnode._unpack_contents(packstr)
 
-def run_benchmarks():
-    print "benchmarking %s" % (unpack,)
-    benchutil.bench(unpack, initfunc=init_for_unpack, TOPXP=12)
-    print "benchmarking %s" % (pack,)
-    benchutil.bench(pack, initfunc=init_for_pack, TOPXP=12)
+def unpack_and_repack(N):
+    return testdirnode._pack_contents(testdirnode._unpack_contents(packstr))
+
+def run_benchmarks(profile=False):
+    for (func, initfunc) in [(unpack, init_for_unpack), (pack, init_for_pack), (unpack_and_repack, init_for_unpack)]:
+        print "benchmarking %s" % (func,)
+        benchutil.bench(unpack_and_repack, initfunc=init_for_unpack, TOPXP=12, profile=profile, profresults="bench_dirnode.prof")
+
+def print_stats():
+    s = hotshot.stats.load("bench_dirnode.prof")
+    s.strip_dirs().sort_stats("time").print_stats(32)
 
 def prof_benchmarks():
-    import hotshot
-    prof = hotshot.Profile("bench_dirnode.prof")
-    prof.runcall(run_benchmarks)
-    prof.close()
+    # This requires pyutil >= v1.3.34.
+    run_benchmarks(profile=True)
 
 if __name__ == "__main__":
     run_benchmarks()
+    # prof_benchmarks()
+    # print_stats()