blob: 47f2535cd8a2d35621bc47f448f325f5307cf3c0 (
plain) (
blame)
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
|
"""
Copyright 2020
This file is part of WarpX.
License: BSD-3-Clause-LBNL
"""
import config
import json
import os
class Benchmark:
'''Holds data and functions for referenc benchmark of one checksum test.
'''
def __init__(self, test_name, data=None):
'''Constructor
Store test name and reference checksum value, either from benchmark
(used for comparison) or from a plotfile (used to reset a benchmark).
@param self The object pointer.
@param test_name Name of test, as found between [] in .ini file.
@param data checksum value (dictionary).
If None, it is read from benchmark.
'''
self.test_name = test_name
self.json_file = os.path.join(config.benchmark_location,
self.test_name + '.json')
if data is None:
self.data = self.get()
else:
self.data = data
def reset(self):
'''Update the benchmark (overwrites reference json file).
@param self The object pointer.
'''
with open(self.json_file, 'w') as outfile:
json.dump(self.data, outfile, sort_keys=True, indent=2)
def get(self):
'''Read benchmark from reference json file.
@param self The object pointer.
'''
with open(self.json_file) as infile:
data = json.load(infile)
return data
|