summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2004-12-01 20:20:13 +0000
committerIan Romanick <idr@us.ibm.com>2004-12-01 20:20:13 +0000
commit596ccff6990adbda4f99dd4b717826b051a0e79e (patch)
tree4864bbbd804aef875960da5f4d6161269f11877f
parent77e297c368be479d08822ea8bd186d7d7f5ea423 (diff)
Prevent possible divide-by-zero error.
-rwxr-xr-xprogs/tests/api_speed.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/progs/tests/api_speed.py b/progs/tests/api_speed.py
index 4f5483064d..0ddaf5836c 100755
--- a/progs/tests/api_speed.py
+++ b/progs/tests/api_speed.py
@@ -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