Prevent possible divide-by-zero error.
authorIan Romanick <idr@us.ibm.com>
Wed, 1 Dec 2004 20:20:13 +0000 (20:20 +0000)
committerIan Romanick <idr@us.ibm.com>
Wed, 1 Dec 2004 20:20:13 +0000 (20:20 +0000)
progs/tests/api_speed.py

index 4f5483064de51a43a9b29241f700e694593093f2..0ddaf5836c901d6b55e628c3764d51b2be8a9bfa 100755 (executable)
@@ -70,10 +70,13 @@ class results:
        def compare_results(self, other):
                for name in self.cycles:
                        if other.cycles.has_key(name):
-                               a = float(self.cycles[name])  / self.iterations
-                               b = float(other.cycles[name]) / other.iterations
-                               p = (100.0 * b / a) - 100.0
-                               print "%- 20s %7.2f - %7.2f = % -6.2f (%+.1f%%)" % (name, a, b, a - b, p)
+                               a = float(self.cycles[name])  / float(self.iterations)
+                               b = float(other.cycles[name]) / float(other.iterations)
+                               if abs( a ) < 0.000001:
+                                   print "a = %f, b = %f" % (a, b)
+                               else:
+                                   p = (100.0 * b / a) - 100.0
+                                   print "%- 20s %7.2f - %7.2f = % -6.2f (%+.1f%%)" % (name, a, b, a - b, p)
                return