-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bench.py
60 lines (51 loc) · 2.13 KB
/
bench.py
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
60
import argparse
import time
import eccodes
import gribberish
if __name__ == '__main__':
parser = argparse.ArgumentParser('Dump a grib 2 file dataset')
parser.add_argument('infile', metavar='i', type=str, help='Path to grib 2 file to ')
args = parser.parse_args()
input_filename = args.infile
with open(input_filename, 'rb') as f:
raw_data = f.read()
mapping = gribberish.parse_grib_mapping(raw_data)
eccodes_times = []
# First run with eccodes
print(f'Processing {len(mapping)} messages with eccodes')
for _, mapped in mapping.items():
offset = mapped[1]
size = mapped[2].message_size
end = offset + size
try:
start = time.time()
message = eccodes.codes_new_from_message(raw_data[offset:end])
data = eccodes.codes_get_array(message, "values")
end = time.time()
eccodes_times.append(end - start)
finally:
eccodes.codes_release(message)
print(f'Mean eccodes time: {(sum(eccodes_times) / len(eccodes_times)) * 1000} ms')
print(f'Median eccodes time: {sorted(eccodes_times)[len(eccodes_times) // 2] * 1000} ms')
print(f'Max eccodes time: {max(eccodes_times) * 1000} ms')
print(f'Min eccodes time: {min(eccodes_times) * 1000} ms')
# Then run with gribberish
gribberish_times = []
# First run with eccodes
print(f'Processing {len(mapping)} messages with gribberish')
for key, mapped in mapping.items():
offset = mapped[1]
size = mapped[2].message_size
end = offset + size
try:
start = time.time()
data = gribberish.parse_grib_array(raw_data, offset)
end = time.time()
gribberish_times.append(end - start)
except:
print(key)
pass
print(f'Mean gribberish time: {(sum(gribberish_times) / len(gribberish_times)) * 1000} ms')
print(f'Median gribberish time: {sorted(gribberish_times)[len(gribberish_times) // 2] * 1000} ms')
print(f'Max gribberish time: {max(gribberish_times) * 1000} ms')
print(f'Min gribberish time: {min(gribberish_times) * 1000} ms')