Skip to content

Commit c912ef0

Browse files
committed
add benchmarks
1 parent 13c6da2 commit c912ef0

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

benchmark/benchmark.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
Created on 04.10.2019
3+
4+
@author: gocht
5+
'''
6+
import benchmark_helper
7+
import pickle
8+
9+
bench = benchmark_helper.BenchmarkEnv()
10+
tests = ["test_1.py", "test_2.py"]
11+
resutls = {}
12+
13+
for test in tests:
14+
resutls[test] = {"profile": {}, "trace": {}, "dummy": {}}
15+
for elem in resutls[test]:
16+
scorep_settings = ["--instrumenter-type={}".format(elem)]
17+
print("#########")
18+
print("{}: {}".format(test, scorep_settings))
19+
print("#########")
20+
for reps in ["1000", "10000", "100000", "1000000", "10000000"]:
21+
times = bench.call(
22+
test,
23+
[reps],
24+
scorep_settings=scorep_settings)
25+
resutls[test][elem][reps] = times
26+
print("{:<8}: {}".format(reps, times))
27+
28+
with open("resutls.pkl", "wb") as f:
29+
pickle.dump(resutls,f)

benchmark/benchmark_helper.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import subprocess
2+
import os
3+
import shutil
4+
import sys
5+
import time
6+
7+
8+
class BenchmarkEnv():
9+
def __init__(self, repetitons=10):
10+
self.env = os.environ.copy()
11+
self.env["SCOREP_ENABLE_PROFILING"] = "false"
12+
self.env["SCOREP_ENABLE_TRACING"] = "true"
13+
self.env["SCOREP_PROFILING_MAX_CALLPATH_DEPTH"] = "98"
14+
self.env["SCOREP_TOTAL_MEMORY"] = "3G"
15+
self.exp_dir = "benchmark_dir"
16+
self.repetitons = repetitons
17+
18+
shutil.rmtree(
19+
self.exp_dir,
20+
ignore_errors=True)
21+
os.mkdir(self.exp_dir)
22+
23+
def __del__(self):
24+
pass
25+
# shutil.rmtree(
26+
# self.exp_dir,
27+
# ignore_errors=True)
28+
29+
def call(self, script="", ops=[], scorep_settings=[]):
30+
"""
31+
return a triple with (returncode, stdout, stderr) from the call to subprocess
32+
"""
33+
34+
self.env["SCOREP_EXPERIMENT_DIRECTORY"] = self.exp_dir + \
35+
"/{}-{}-{}".format(script, ops, scorep_settings)
36+
37+
arguments = [sys.executable, "-m", "scorep"]
38+
arguments.extend(scorep_settings)
39+
arguments.append(script)
40+
arguments.extend(ops)
41+
42+
runtimes = []
43+
for i in range(self.repetitons):
44+
begin = time.time()
45+
out = subprocess.run(
46+
arguments,
47+
env=self.env,
48+
stdout=subprocess.PIPE,
49+
stderr=subprocess.PIPE)
50+
end = time.time()
51+
assert(out.returncode == 0)
52+
53+
runtime = end - begin
54+
runtimes.append(runtime)
55+
56+
return runtimes

benchmark/test_1.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import sys
2+
3+
result = 0
4+
for i in range(int(sys.argv[1])):
5+
result += 1
6+
print(result)

benchmark/test_2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
Created on 04.10.2019
3+
4+
@author: gocht
5+
'''
6+
import sys
7+
8+
9+
def add(val):
10+
return val + 1
11+
12+
13+
result = 0
14+
for i in range(int(sys.argv[1])):
15+
result = add(result)
16+
print(result)

0 commit comments

Comments
 (0)