-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_test.py
109 lines (88 loc) · 2.82 KB
/
benchmark_test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from daqmx_class import DaqmxSession
import time
import xlsxwriter
import datetime
import os.path
def single_method_benchmark(session, method_to_test, trials):
session.open()
results = []
trial = 1
for trial in range(trial, trials+1):
start_time = time.perf_counter()
method_to_test()
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print(elapsed_time)
print(trial)
results.append([trial, elapsed_time])
trial += 1
session.close()
return results
def open_benchmark(session, trials):
start_time = time.perf_counter()
session.open()
end_time = time.perf_counter()
session.close()
elapsed_time = end_time - start_time
return elapsed_time
def close_benchmark(session, trials):
session.open()
start_time = time.perf_counter()
session.close()
end_time = time.perf_counter()
elapsed_time = end_time - start_time
return elapsed_time
# ------------- LOGGING SETUP --------------
auto_incr_test_num = True
test_name = "PythonBenchmarkDAQmxAI"
test_num = 1
now = datetime.datetime.now()
file_name = test_name + "_" + str(test_num) + ".xlsx"
if auto_incr_test_num:
while os.path.isfile(file_name):
print('File exists, auto-increasing test number...')
test_num += 1
file_name = test_name + "_" + str(test_num) + ".xlsx"
print(file_name)
try:
xlsxwriter.Workbook(file_name).close()
except PermissionError as perm_error:
print(perm_error)
print("Check whether file is open in Excel.")
quit()
workbook = xlsxwriter.Workbook(file_name)
worksheet = workbook.add_worksheet()
# Rows and columns are zero indexed.
test_descrip_row = 0
test_results_row = test_descrip_row + 1
data_label_row = test_results_row + 2
col = 0
worksheet.set_column(0, 4, 25)
worksheet.write(test_descrip_row, 0, "Test Name")
worksheet.write(test_descrip_row, 1, test_name)
worksheet.write(test_descrip_row, 2, "Date and Time")
worksheet.write(test_descrip_row, 3, str(now))
worksheet.write(data_label_row, 0, "Trial")
worksheet.write(data_label_row, 1, "Time(s)")
row = data_label_row + 1
# ----------------- DRIVER TEST --------------
session = DaqmxSession()
trials = 6
results = single_method_benchmark(session, session.read_std, trials)
print(session.data)
print(len(session.data))
print(results)
# ------------- LOG TO FILE --------------
for x, y in (results):
worksheet.write(row, col, x)
worksheet.write(row, col + 1, y)
row += 1
average = 0
for x in results:
average = average + x[1]
average = average / len(results)
worksheet.write(test_results_row, 0, "Average Time (s)")
worksheet.write(test_results_row, 1, average)
worksheet.write(test_results_row, 2, "Num of Iterations")
worksheet.write(test_results_row, 3, row-(data_label_row+1)) # Perhaps revise this.
workbook.close()