changeset 1270:bf991ca28f23

Added better timing capability to runtime.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Fri, 09 Oct 2009 14:15:05 +0200
parents f91b28a6cbbe
children 26f7a133172a
files apps/benchmark.py viff/runtime.py
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/apps/benchmark.py	Fri Oct 09 13:04:18 2009 +0200
+++ b/apps/benchmark.py	Fri Oct 09 14:15:05 2009 +0200
@@ -358,11 +358,9 @@
     needed_data = eval(needed_data)
 
 if options.needed_data != "" and options.pc != "":
-    print "A1"
     bases = (benchmark,) + (NeededDataBenchmarkStrategy,) + (object,)
     options.pc = eval(options.pc)
 else:
-    print "B1"
     bases = (benchmark,) + (SelfcontainedBenchmarkStrategy,) + (object,)
 benchmark = type("ExtendedBenchmark", bases, {})
 
@@ -382,7 +380,6 @@
 pre_runtime.addCallback(update_args, options)
 
 def do_benchmark(runtime, operation, benchmark, *args):
-    print "db"
     benchmark(runtime, operation).benchmark(*args)
 
 pre_runtime.addCallback(do_benchmark, operation, benchmark, needed_data, options.pc)
--- a/viff/runtime.py	Fri Oct 09 13:04:18 2009 +0200
+++ b/viff/runtime.py	Fri Oct 09 14:15:05 2009 +0200
@@ -803,7 +803,14 @@
         example of a method fulfilling this interface.
         """
 
-        def update(results, program_counters):
+        def update(results, program_counters, start_time, count, what):
+            stop = time.time()
+
+            print
+            print "Total time used: %.3f sec" % (stop - start_time)
+            print "Time per %s operation: %.0f ms" % (what, 1000*(stop - start_time) / count)
+            print "*" * 6
+
             # We concatenate the sub-lists in results.
             results = sum(results, [])
 
@@ -828,7 +835,10 @@
             func = getattr(self, generator)
             results = []
             items = 0
+            count = 0
+            start_time = time.time()
             while items < len(program_counters):
+                count += 1
                 self.increment_pc()
                 self.fork_pc()
                 item_count, result = func(*args,
@@ -837,7 +847,7 @@
                 results.append(result)
                 self.unfork_pc()
             ready = gatherResults(results)
-            ready.addCallback(update, program_counters)
+            ready.addCallback(update, program_counters, start_time, count, generator)
             wait_list.append(ready)
             self.unfork_pc()
         return DeferredList(wait_list)