picosdk-python-wrappers
picosdk-python-wrappers copied to clipboard
NumPy is optimized for vectorized operations, which makes it
Optimization of ADC acquisition
NumPy is optimized for vectorized operations, which makes it significantly faster than Python loops. To improve the speed of your calculation, try using NumPy directly instead of list comprehensions.
This eliminates the loop altogether, allowing NumPy to perform element-wise operations efficiently. You should see a noticeable speed improvement, especially for large arrays.
We tested these with 250 Mega points and adquisition took 96.072 s using your code
bufferV = [(x * range) / maxADC.value for x in bufferADC]
by changing to:
bufferADC_np = np.array(bufferADC, dtype=np.int64)
bufferV = (bufferADC_np * range) / maxADC.value
took 1.347 s. And if you premultiply the factor
normRange = range/maxADC.value
bufferV = np.ctypeslib.as_array(bufferADC) * normRange
reduces to 1.022 s
Enjoy :)
Fixes #.
Changes proposed in this pull request:
- Use numpy to deal with buffers
- Use vectorial multiplication instead of for looping