squeeze out some performance
Jeremy Sanders
jeremy at jeremysanders.net
Fri Dec 6 04:46:46 EST 2013
Robert Voigtländer wrote:
> I try to squeeze out some performance of the code pasted on the link
> below. http://pastebin.com/gMnqprST
>
> The code will be used to continuously analyze sonar sensor data. I set
> this up to calculate all coordinates in a sonar cone without heavy use of
> trigonometry (assuming that this way is faster in the end).
>
> I optimized as much as I could. Maybe one of you has another bright idea
> to squeeze out a bit more?
This sort of code is probably harder to make faster in pure python. You
could try profiling it to see where the hot spots are. Perhaps the choice of
arrays or sets might have some speed impact.
One idea would be to use something like cython to compile your python code
to an extension module, with some hints to the types of the various values.
I would go down the geometry route. If you can restate your problem in terms
of geometry, it might be possible to replace all that code with a few numpy
array operations.
e.g. for finding pixels in a circle of radius 50
import numpy as np
radiussqd = np.fromfunction(lambda y,x: (y-50)**2+(x-50)**2, (100,100) )
all_y, all_x = np.indices((100,100))
yvals = all_y[radiussqd < 50**2]
Jeremy
More information about the Python-list
mailing list