-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz_test_speed.py
147 lines (98 loc) · 4.3 KB
/
z_test_speed.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from mod_software.SI import si
import numpy as np
import time
import h5py
import matplotlib.pyplot as plt
from tqdm import tqdm
from scipy.stats import linregress
import os
from datetime import datetime
'''
Testing speed of system.
THere are different ways of using GPIO:
- https://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/
- Can use GPIO package
- Can use others like WiringPi2, or pigpio, Gpiozero
Check Package version:
- pip3 show ____
Ways to speed up:
- use latest RPi.GPIO 0.7.1!!! (https://sourceforge.net/p/raspberry-gpio-python/wiki/install/)
- try pigpio (https://abyz.me.uk/rpi/pigpio/python.html)
'''
ADCfclk = 2000000 # 2000000
obj = si(Rshunt=470, ADCspeed=ADCfclk) # 14000 , 47000, , electrode11='in'
in_pins = [1,9,2]
out_pins = [2,3,4]
numS = 1 # 30
rng = np.random.default_rng(0)
num_v = 10000
s = (num_v, len(in_pins))
Vins = rng.uniform(-5,5, size=s)
t_dac_total = 0
t_dac_spi = 0
t_dac_gpio = 0
t_adc_total = 0
t_adc_capture_total = 0
t_adc_sample = 0
t_adc_per_sample = []
t_instance = []
tic_start = time.time()
for v in Vins:
tic = time.time()
# # Set Voltages
for i, inPin in enumerate(in_pins):
V_dac, t_spi, t_gpio, t_total = obj.SetVoltage(electrode=inPin, voltage=v[i], timings=1)
t_dac_total += t_total
t_dac_spi += t_spi
t_dac_gpio += t_gpio
# # Read Outputs
for col, OP in enumerate(out_pins):
Vop, t_total_all, t_total, t_av_sample, t_burst = obj.ReadVoltageFast(OP, ret_type=0, nSamples=numS, timings=1)
'''###
Vop, t_total_all, t_total, t_sample = obj.ReadVoltageFastest(OP, nSamples=1, timings=1)
t_av_sample = t_sample
t_burst = t_sample
# '''
t_adc_total += t_total_all
t_adc_capture_total += t_total
t_adc_sample += t_burst
t_adc_per_sample.append(t_av_sample)
t_instance.append(time.time() - tic)
obj.fin()
total = time.time()-tic_start
print("\n>> Total Time = %f <<" % (total))
print("\nTotal DAC Time = %f (%.3f p of total) " % (t_dac_total, t_dac_total/total))
print(" - DAC SPI Time = %f (%.3f p of total) " % (t_dac_spi, t_dac_spi/total))
print(" - DAC GPIO Time = %f (%.3f p of total) " % (t_dac_gpio, t_dac_gpio/total))
print(" > Total per DAC freq = %f" % (len(in_pins)*num_v/t_dac_total))
print("\nTotal ADC Time = %f (%.3f p of total) " % (t_adc_total, t_adc_total/total))
print("Using %d bust sample groups" % (numS))
print(" - ADC capture function Time = %f (%f p of total) " % (t_adc_capture_total, t_adc_capture_total/total))
print(" - ADC Reading Time = %f (%.3f p of total) " % (t_adc_sample, t_adc_sample/total))
print(" - ADC AvSample Time = %f (%.3f p of total), est time sampling ~ %f, rate: %f" % (np.mean(t_adc_per_sample), np.mean(t_adc_per_sample)/total, np.mean(t_adc_per_sample)*num_v*numS*len(out_pins), 1/np.mean(t_adc_per_sample)))
print(" > Total per ADC channel & sample freq = %f" % (len(out_pins)*numS*num_v/t_adc_total))
other_total = total-t_dac_spi-t_dac_gpio-t_adc_sample
print("\nTotal Other Time = %f (%.3f p of total) " % (other_total, other_total/total))
other_dac = t_dac_total-t_dac_spi-t_dac_gpio
print(" - DAC other Time = %f (%.3f p of total) " % (other_dac, other_dac/total))
other_adc = t_adc_total-t_adc_sample
print(" - ADC other Time = %f (%.3f p of total) " % (other_adc, other_adc/total))
other_other = other_total - other_dac - other_adc
print(" - Other other Time = %f (%.3f p of total) " % (other_other, other_other/total))
print("\nTime to do all %d readings = %f" % (num_v, total))
print(" - Instance [%d set]/[%d read] average time = %f" % (len(in_pins), len(out_pins), np.mean(t_instance)))
print(" - Instance [%d set]/[%d read] average rate = %f" % (len(in_pins), len(out_pins), 1/np.mean(t_instance)))
print(" - Instance [%d set]/[%d read] average DAC time = %f" % (len(in_pins), len(out_pins), t_dac_total/num_v))
print(" - Instance [%d set]/[%d read] average ADC time = %f" % (len(in_pins), len(out_pins), t_adc_total/num_v))
tic = time.time()
for j in range(num_v*numS):
time.time()
print("\n>>Time it takes to call time.time() for %d : %f" % (num_v*numS, time.time()-tic))
tic = time.time()
for v in Vins:
a = (v+10)*5
print("Individual multiplication:", time.time()-tic)
tic = time.time()
a = (Vins+10)*5
print("array multiplication:", time.time()-tic)
# fin