1""" This module benchmarks some of the CDB API functions. """
6import dummydata_generator
7from ..factory
import APIFactory
11log_file = logging.FileHandler(filename=
'benchmarking_dummydata.log', mode=
'a', encoding=
'utf-8')
12fmt = logging.Formatter()
13log_file.setFormatter(fmt)
14logger = logging.Logger(name=
'benchmarking', level=logging.INFO)
15logger.addHandler(log_file)
16logger.info(msg=time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime()))
17logger.info(msg=
'Benchmarking start - Record code execution time :')
18logger.info(msg=
'Method_name wall_time cpu_time')
20if __name__ ==
"__main__":
23 cdb_api = factory.construct_DB_API(
"conditionsDatabase/tests/test_mongodb/test_mongodb_config.yml")
26 wall_time_start = time.time()
27 cpu_time_start = time.clock()
29 cdb_api.add_detector(
"detector_one")
31 wall_time_end = time.time()
32 cpu_time_end = time.clock()
33 logger.info(msg=
'add One detector to the database%15.6f%13.6f' % (
34 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
37 wall_time_start = time.time()
38 cpu_time_start = time.clock()
40 for i
in range(1, 100):
41 cdb_api.add_detector(
"detector_i" + i)
43 wall_time_end = time.time()
44 cpu_time_end = time.clock()
45 logger.info(msg=
'add 100 detectors to the database%15.6f%13.6f' % (
46 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
49 wall_time_start = time.time()
50 cpu_time_start = time.clock()
52 cdb_api.list_detectors()
54 wall_time_end = time.time()
55 cpu_time_end = time.clock()
56 logger.info(msg=
'List detectors%15.6f%13.6f' % (
57 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
62 group_detector_parent = []
63 dummydata_generator.create_multilevel_detectors(5, 5,
"detector",
None, group_detector_parent)
65 wall_time_start = time.time()
66 cpu_time_start = time.clock()
68 for detector_and_parent
in group_detector_parent:
69 detector_name = detector_and_parent[0]
70 detector_parent = detector_and_parent[1]
71 cdb_api.add_detector(detector_name, detector_parent)
72 values = {
"T853_MA_853": [814, 973, 65]}
74 reconstructed_detector_id =
""
75 if detector_parent
is None:
76 reconstructed_detector_id = detector_name
78 reconstructed_detector_id = detector_parent +
"/" + detector_name
80 cdb_api.add_condition(reconstructed_detector_id,
"daniel",
"tag1", values,
"calibration")
82 wall_time_end = time.time()
83 cpu_time_end = time.clock()
85 msg=
'create Complex Structure%15.6f%13.6f' % (wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
89 daniel = dummydata_generator.create_big_daniel()
90 wall_time_start = time.time()
91 cpu_time_start = time.clock()
92 cdb_api.add_condition(
"detector1/subdetector1/subsubdetector1/subsubsubdetector1/subsubsubsubdetector1",
93 "daniel",
"tag2", daniel,
"calibration")
94 wall_time_end = time.time()
95 cpu_time_end = time.clock()
96 logger.info(msg=
'add One massive Condition to the deepest level%15.6f%13.6f' % (
97 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
100 wall_time_start = time.time()
101 cpu_time_start = time.clock()
102 cdb_api.get_condition_by_name_and_tag(
103 "detector1/subdetector1/subsubdetector1/subsubsubdetector1/subsubsubsubdetector1",
"daniel",
"tag2")
104 wall_time_end = time.time()
105 cpu_time_end = time.clock()
106 logger.info(msg=
'get a massive Condition by name from the deepest level%15.6f%13.6f' % (
107 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
110 wall_time_start = time.time()
111 cpu_time_start = time.clock()
112 cdb_api.get_conditions_by_tag(
113 "detector1/subdetector1/subsubdetector1/subsubsubdetector1/subsubsubsubdetector1",
"tag1")
114 wall_time_end = time.time()
115 cpu_time_end = time.clock()
116 logger.info(msg=
'get Conditions by tag from the deepest level%15.6f%13.6f' % (
117 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
120 wall_time_start = time.time()
121 cpu_time_start = time.clock()
122 cdb_api.update_condition_by_name_and_tag(
123 "detector1/subdetector1/subsubdetector1/subsubsubdetector1/subsubsubsubdetector1",
127 wall_time_end = time.time()
128 cpu_time_end = time.clock()
129 logger.info(msg=
'update a Condition at the deepest level%15.6f%13.6f' % (
130 wall_time_end - wall_time_start, cpu_time_end - cpu_time_start))
This class creates an instance of the specified database API.