forked from LovisaLugnegard/exjobb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarking.py
More file actions
59 lines (44 loc) · 1.47 KB
/
benchmarking.py
File metadata and controls
59 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import time
"""
Use like this to generate CSV output:
python3 example_simulator_no_flask_dummy_set.py | tee >(grep --line-buffered "^benchmarking," > benchmarking.csv)
python3 run_prod_pipeline_from_volume.py | tee >(grep --line-buffered "^benchmarking," > benchmarking.csv)
"""
__enabled = False
__printed_header = False
def enable():
global __enabled
__enabled = True
def start_benchmark():
return time.time()
def end_benchmark(file, topic, started_at_time, description='', number_of_bytes=-1):
global __enabled
if not __enabled:
return
global __printed_header
ended_time = time.time()
if not __printed_header:
__printed_header = True
print(','.join([
'benchmarking',
'file',
'topic',
'description',
'started_at_time',
'ended_time',
'duration_secs',
'number_of_bytes']))
columns = ['benchmarking',
file,
topic,
description,
str(started_at_time),
str(ended_time),
str(ended_time - started_at_time), # TODO: ensure sci-not can be parsed ?
str(number_of_bytes)]
row = ','.join(columns)
print(row, flush=True) # Flushing helps with docker containers
if __name__ == '__main__':
enable()
start = start_benchmark()
end_benchmark('foo_file','foo_topic', start, description='foo description', number_of_bytes=5)