Skip to content

Commit cc0915e

Browse files
authored
Merge pull request #51 from score-p/benchmark
Add some performance benchmarks.
2 parents 13c6da2 + 72200a2 commit cc0915e

5 files changed

Lines changed: 144 additions & 0 deletions

File tree

benchmark/benchmark.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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(repetitions=11)
10+
tests = ["test_1.py", "test_2.py"]
11+
results = {}
12+
13+
for test in tests:
14+
results[test] = {"profile": {}, "trace": {}, "dummy": {}, "None": {}}
15+
for instrumenter in results[test]:
16+
if instrumenter is "None":
17+
enable_scorep = False
18+
scorep_settings = []
19+
else:
20+
enable_scorep = True
21+
scorep_settings = ["--instrumenter-type={}".format(instrumenter)]
22+
23+
print("#########")
24+
print("{}: {}".format(test, scorep_settings))
25+
print("#########")
26+
for reps in ["1000", "10000", "100000", "1000000", "10000000"]:
27+
times = bench.call(
28+
test,
29+
[reps],
30+
enable_scorep,
31+
scorep_settings=scorep_settings)
32+
results[test][instrumenter][reps] = times
33+
print("{:<8}: {}".format(reps, times))
34+
35+
with open("results.pkl", "wb") as f:
36+
pickle.dump(results, f)

benchmark/benchmark_helper.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import subprocess
2+
import os
3+
import shutil
4+
import sys
5+
import time
6+
7+
8+
class BenchmarkEnv():
9+
def __init__(self, repetitions=10):
10+
self.env = os.environ.copy()
11+
self.env["SCOREP_ENABLE_PROFILING"] = "false"
12+
self.env["SCOREP_ENABLE_TRACING"] = "false"
13+
self.env["SCOREP_PROFILING_MAX_CALLPATH_DEPTH"] = "98"
14+
self.env["SCOREP_TOTAL_MEMORY"] = "3G"
15+
self.exp_dir = "benchmark_dir"
16+
self.repetitions = repetitions
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=[], enable_scorep=True, scorep_settings=[]):
30+
self.env["SCOREP_EXPERIMENT_DIRECTORY"] = self.exp_dir + \
31+
"/{}-{}-{}".format(script, ops, scorep_settings)
32+
33+
arguments = [sys.executable]
34+
if enable_scorep:
35+
arguments.extend(["-m", "scorep"])
36+
arguments.extend(scorep_settings)
37+
arguments.append(script)
38+
arguments.extend(ops)
39+
40+
runtimes = []
41+
for i in range(self.repetitions):
42+
begin = time.time()
43+
out = subprocess.run(
44+
arguments,
45+
env=self.env,
46+
stdout=subprocess.PIPE,
47+
stderr=subprocess.PIPE)
48+
end = time.time()
49+
assert(out.returncode == 0)
50+
51+
runtime = end - begin
52+
runtimes.append(runtime)
53+
54+
return runtimes

benchmark/run.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
#SBATCH --time=04:00:00
3+
#SBATCH --exclusive
4+
#SBATCH -p haswell
5+
#SBATCH -A p_readex
6+
#SBATCH -N 1
7+
#SBATCH --ntasks-per-node=1
8+
#SBATCH -c 24
9+
#SBATCH --comment=no_monitoring
10+
#SBATCH --job-name benchmark_python
11+
12+
13+
module load Python/3.6.6-foss-2019a
14+
15+
module use /home/gocht/modules
16+
module load scorep/scorep-6.0-python3.6.6-foss-2019a
17+
# Score-P 6.0 build with
18+
# ../configure --prefix=/home/gocht/sw/scorep/scorep-6.0-python3.6.6-foss-2019a --enable-shared
19+
# scorep_binding_python git sha: 8d35a668b0a59480e4e7fd9f43ae50949d807241
20+
# installed in virtual environment
21+
22+
. ~/virtenv/Python-3.6.6-foss-2019a/bin/activate
23+
24+
srun taskset -c 0 python benchmark.py

benchmark/test_1.py

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

benchmark/test_2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
iterations = int(sys.argv[1])
15+
iteration_list = list(range(iterations))
16+
17+
for i in iteration_list:
18+
result = add(result)
19+
20+
assert(result == iterations)

0 commit comments

Comments
 (0)