Jelajahi Sumber

Make a single unified benchmark script

Yentl Van Tendeloo 7 tahun lalu
induk
melakukan
a40f64422f
3 mengubah file dengan 60 tambahan dan 43 penghapusan
  1. 60 0
      model/benchmark.py
  2. 0 11
      model/run_real.py
  3. 0 32
      model/sim_loop.py

+ 60 - 0
model/benchmark.py

@@ -0,0 +1,60 @@
+from subprocess import call
+import time
+
+def run_real(samples):
+    with open("model/results_real", 'w') as f:
+        for _ in range(samples):
+            start = time.time()
+            call(["pypy", "-m", "pytest", "integration/test_powerwindow.py", "-k", "fast", "-x"])
+            print("Time to execute: " + str(time.time() - start))
+            f.write(str(time.time() - start))
+            f.write("\n")
+            f.flush()
+
+def run_simulation(latency):
+    import sys
+    sys.path.append("model")
+    from model import simulate
+    print("SIMULATE for " + str(latency))
+    result = simulate(latency)
+    print(result)
+    return result
+
+def benchmark(parallel, to_run):
+    if parallel:
+        from multiprocessing import Pool
+        pool = Pool(processes=4)
+        results = pool.map(run_simulation, to_run)
+    else:
+        results = map(run_simulation, to_run)
+    return results
+
+def benchmark_mvs(parallel, latency_range):
+    to_run = [{"mvk2mvs_latency": i} for i in latency_range]
+    results = benchmark(parallel, to_run)
+
+    print(results)
+    with open("model/results_mvs_latency", 'w') as f:
+        for latency, result in zip(to_run, results):
+            sim, exe = result
+            f.write("%s %s %s\n" % (latency, sim, exe))
+            f.flush()
+
+def benchmark_mvi(parallel, latency_range):
+    to_run = [{"mvi2mvk_latency": i} for i in latency_range]
+    results = benchmark(parallel, to_run)
+
+    print(results)
+    with open("model/results_mvi_latency", 'w') as f:
+        for latency, result in zip(to_run, results):
+            sim, exe = result
+            f.write("%s %s %s\n" % (latency, sim, exe))
+            f.flush()
+
+if __name__ == "__main__":
+    benchmark_mvs(parallel = False, latency_range=[0.0, 0.5])
+    benchmark_mvi(parallel = False, latency_range=[0.0, 0.5])
+    run_real(samples = 2)
+    #benchmark_mvs(parallel = False, latency_range=[0.0, 0.0017, 0.012, 0.02, 0.1, 0.5])
+    #benchmark_mvi(parallel = False, latency_range=[0.0, 0.0017, 0.012, 0.02, 0.1, 0.5])
+    #run_real(samples = 10)

+ 0 - 11
model/run_real.py

@@ -1,11 +0,0 @@
-from subprocess import call
-import time
-
-with open("real_execution_time", 'w') as f:
-    for _ in range(100):
-        start = time.time()
-        call(["pypy", "-m", "pytest", "integration/test_powerwindow.py", "-k", "fast", "-x"])
-        print("Time to execute: " + str(time.time() - start))
-        f.write(str(time.time() - start))
-        f.write("\n")
-        f.flush()

+ 0 - 32
model/sim_loop.py

@@ -1,32 +0,0 @@
-# Run some experiments and store all values
-to_run = []
-for latency in [0 + i * 0.001 for i in range(0, 50)]:
-    to_run.append((latency, 0.0))
-for latency in [0 + i * 0.001 for i in range(50, 600, 50)]:
-    to_run.append((latency, 0.0))
-for latency in [0 + i * 0.001 for i in range(0, 50)]:
-    to_run.append((0.0, latency))
-for latency in [0 + i * 0.001 for i in range(50, 600, 50)]:
-    to_run.append((latency, 0.0))
-
-to_run = [(0.0, 0.0), (0.2, 0.2), (0.1, 0.1), (0.0, 0.2)]
-print(to_run)
-print("NR simulations: " + str(len(to_run)))
-
-def run_simulation(latency):
-    import sys
-    sys.path.append("model")
-    from model import simulate
-    latency_mvi, latency_mvs = latency
-    print("SIMULATE for " + str(latency))
-    result = simulate({"mvi2mvk_latency": 0.0, "mvk2mvs_latency": 0.0})
-    print("(%s, %s) --> %s" % (latency_mvi, latency_mvs, result))
-    return result
-
-from multiprocessing import Pool
-pool = Pool(processes=4)
-results = pool.map(run_simulation, to_run)
-
-print(dict(to_run, results))
-with open("simloop_results", 'w') as f:
-    json.dump(f, results)