changeset 879:67a0628c2f83

Track number of comparisons.
author Martin Geisler <mg@daimi.au.dk>
date Fri, 08 Aug 2008 10:39:54 +0200
parents f39882ce0e89
children 25d1109d5b60
files apps/sort.py
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/apps/sort.py	Fri Aug 08 10:27:24 2008 +0200
+++ b/apps/sort.py	Fri Aug 08 10:39:54 2008 +0200
@@ -74,6 +74,7 @@
 
     def __init__(self, runtime):
         self.rt = runtime
+        self.comparisons = 0
 
         array = self.make_array()
         sorted = self.sort(array)
@@ -85,6 +86,7 @@
         dprint("Sorted array:   %s", sorted)
 
         def finish(_):
+            print "Made %d comparisons" % self.comparisons
             runtime.shutdown()
         sorted.addCallback(finish)
 
@@ -123,6 +125,7 @@
                 bitonic_merge(low + m, n - m, ascending)
 
         def compare(i, j, ascending):
+            self.comparisons += 1
 
             def xor(a, b):
                 # TODO: We use this simple xor until