viff

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 diff
     1.1 --- a/apps/sort.py	Fri Aug 08 10:27:24 2008 +0200
     1.2 +++ b/apps/sort.py	Fri Aug 08 10:39:54 2008 +0200
     1.3 @@ -74,6 +74,7 @@
     1.4  
     1.5      def __init__(self, runtime):
     1.6          self.rt = runtime
     1.7 +        self.comparisons = 0
     1.8  
     1.9          array = self.make_array()
    1.10          sorted = self.sort(array)
    1.11 @@ -85,6 +86,7 @@
    1.12          dprint("Sorted array:   %s", sorted)
    1.13  
    1.14          def finish(_):
    1.15 +            print "Made %d comparisons" % self.comparisons
    1.16              runtime.shutdown()
    1.17          sorted.addCallback(finish)
    1.18  
    1.19 @@ -123,6 +125,7 @@
    1.20                  bitonic_merge(low + m, n - m, ascending)
    1.21  
    1.22          def compare(i, j, ascending):
    1.23 +            self.comparisons += 1
    1.24  
    1.25              def xor(a, b):
    1.26                  # TODO: We use this simple xor until