[pypy-svn] r70611 - pypy/benchmarks/unladen_swallow

fijal at codespeak.net fijal at codespeak.net
Fri Jan 15 15:53:02 CET 2010


Author: fijal
Date: Fri Jan 15 15:53:01 2010
New Revision: 70611

Modified:
   pypy/benchmarks/unladen_swallow/perf.py
Log:
Consistently return an object from different ways of running benchmarks


Modified: pypy/benchmarks/unladen_swallow/perf.py
==============================================================================
--- pypy/benchmarks/unladen_swallow/perf.py	(original)
+++ pypy/benchmarks/unladen_swallow/perf.py	Fri Jan 15 15:53:01 2010
@@ -372,6 +372,13 @@
                  " %(delta_std)s\n" + self.get_timeline())
                  % self.__dict__)
 
+class ResultError(object):
+    def __init__(self, e):
+        self.msg = str(e)
+
+    def string_representation(self):
+        return self.msg
+
 class MemoryUsageResult(object):
     def __init__(self, max_base, max_changed, delta_max, chart_link):
         self.max_base = max_base
@@ -389,6 +396,16 @@
                  " %(delta_max)s\n" + self.get_usage_over_time())
                  % self.__dict__)
 
+class SimpleComparisonResult(object):
+    def __init__(self, base_time, changed_time, time_delta):
+        self.base_time    = base_time
+        self.changed_time = changed_time
+        self.time_delta   = time_delta
+
+    def string_representation(self):
+        return ("%(base_time)f -> %(changed_time)f: %(time_delta)s"
+                % self.__dict__)
+
 def CompareMemoryUsage(base_usage, changed_usage, options):
     """Like CompareMultipleRuns, but for memory usage."""
     max_base, max_changed = max(base_usage), max(changed_usage)
@@ -422,8 +439,8 @@
         *args, **kwargs: will be passed through to benchmark_function. 
 
     Returns:
-        String summarizing the differences between the two benchmark runs,
-        suitable for human consumption.
+        An object representing differences between the two benchmark runs.
+        Comes with string_representation method.
     """
     try:
         changed_data = benchmark_function(changed_python, options,
@@ -431,7 +448,7 @@
         base_data = benchmark_function(base_python, options,
                                        *args, **kwargs)
     except subprocess.CalledProcessError, e:
-        return str(e)
+        return ResultError(e)
 
     return CompareBenchmarkData(base_data, changed_data, options)
 
@@ -646,8 +663,7 @@
         # below.
         base_time, changed_time = base_times[0], changed_times[0]
         time_delta = TimeDelta(base_time, changed_time)
-        return ("%(base_time)f -> %(changed_time)f: %(time_delta)s"
-                % locals())
+        return SimpleComparisonResult(base_time, changed_time, time_delta)
 
     # Create a chart showing iteration times over time. We round the times so
     # as not to exceed the GET limit for Google's chart server.



More information about the Pypy-commit mailing list