Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Short answer</strong>: Write it in C!</p> <h1>Long answer</h1> <p>Using the cookbook about <a href="http://www.scipy.org/Cookbook/C_Extensions/NumPy_arrays" rel="nofollow noreferrer">numpy arrays</a> I rewrote the trapezoidal convolution method in C. In order to use the C code one requires three files (<a href="https://gist.github.com/1626919" rel="nofollow noreferrer">https://gist.github.com/1626919</a>)</p> <ul> <li>The C code (performancemodule.c).</li> <li>The setup file to build the code and make it callable from python (performancemodulesetup.py).</li> <li>The python file that makes use of the C extension (performancetest.py)</li> </ul> <p>The code should run upon downloading by doing the following</p> <ul> <li>Adjust the include path in <code>performancemodule.c</code>.</li> <li><p>Run the following</p> <p>python performancemodulesetup.py build python performancetest.py</p></li> </ul> <p>You may have to copy the library file <code>performancemodule.so</code> or <code>performancemodule.dll</code> into the same directory as <code>performancetest.py</code>.</p> <h1>Results and performance</h1> <p>The results agree neatly with one another as shown below:</p> <p><img src="https://i.stack.imgur.com/6r7ss.png" alt="Comparison of methods"></p> <p>The performance of the C method is even better than scipy's convolve method. Running 10k convolutions with array length 50 requires</p> <pre><code>convolve (seconds, microseconds) 81 349969 scipy.signal.convolve (seconds, microseconds) 1 962599 convolve in C (seconds, microseconds) 0 87024 </code></pre> <p>Thus, the C implementation is about <strong>1000 times</strong> faster than the python implementation and a bit more than 20 times as fast as the scipy implementation (admittedly, the scipy implementation is more versatile).</p> <p><strong>EDIT</strong>: This does not solve the original question exactly but is sufficient for my purposes.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload