Преглед изворни кода

Define 'run_perf_test' in 'performance/utils.py'

jonathanvdc пре 8 година
родитељ
комит
0c2589b938

+ 1 - 1
performance/test_fibonacci.py

@@ -11,7 +11,7 @@ class TestFibonacci(unittest.TestCase):
 
     def fibonacci(self, mode):
         print(
-            utils.run_file_single_output(
+            utils.run_perf_test(
                 ["test_harness.alc", "fibonacci.alc", "primitives.alc"],
                 [20, 0],
                 mode))

+ 1 - 1
performance/test_matrix_create.py

@@ -11,7 +11,7 @@ class TestMatrixCreate(unittest.TestCase):
 
     def create_matrix(self, mode):
         print(
-            utils.run_file_single_output(
+            utils.run_perf_test(
                 ["test_harness.alc", "matrix.alc",
                  "matrix_create.alc", "primitives.alc",
                  "random.alc"],

+ 1 - 1
performance/test_matrix_gauss_jordan.py

@@ -11,7 +11,7 @@ class TestMatrixGaussJordan(unittest.TestCase):
 
     def matrix_gauss_jordan(self, mode):
         print(
-            utils.run_file_single_output(
+            utils.run_perf_test(
                 ["test_harness.alc", "matrix.alc",
                  "matrix_gauss_jordan.alc", "primitives.alc",
                  "random.alc"],

+ 9 - 0
performance/utils.py

@@ -223,6 +223,15 @@ def run_file_single_output(files, parameters, mode):
        and then collects and returns a single output."""
     return run_file_fixed_output_count(files, parameters, mode, 1)[0]
 
+def run_perf_test(files, parameters, mode, n_iterations=1):
+    """Compiles the given sequence of files, feeds them the given input in the given mode,
+       and then collects their output. This process is repeated n_iterations times. The
+       return value is the average of all outputs."""
+    result = 0.0
+    for _ in xrange(n_iterations):
+        result += float(run_file_single_output(files, parameters, mode)) / float(n_iterations)
+    return result
+
 def format_output(output):
     """Formats the output of `run_file_to_completion` as a string."""
     return '\n'.join(output)