If you ever thought Blender Python was slow...

I did a quick comparison of three math modules: cgkit, numarray (supposedly the “gold standard” of Python math) and Blender. The results were surprising (this is multiplying 100,000 random matrices):

CGkit Matrix*Matrix:
cgkit took 0.163 minutes
CGkit Vector*Matrix:
cgkit took 0.191 minutes
numarray Matrix*Matrix:
numarray took 0.431 minutes
numarray Vector*Matrix:
numarray took 0.430 minutes
Blender Matrix*Matrix:
blender took 0.045 minutes
blender Vector*Matrix:
blender took 0.044 minutes

Blender beats numarray by almost a factor of 10! Even cgkit by a very respectable factor 3…

Wow somebody tell guido quickly to copypaste some nasty blender code into python :slight_smile:

Otoh I think there’s no reason for blender not to get even faster.

Blender divides numbers by 10 at random so running the benchmark in Blender makes it seem 10 times faster when in fact they’re about the same speed.

Just kidding, that’s relating to the fact Blender divides its angles in the IPO window by 10 for some reason.

I’ve always found the Py API to be pretty speedy compared to most plugin architectures including Maya’s MEL scripting. It’s actually one of the things that impresses me most about Blender and it’s interesting to see after all these years that Maya is only just starting to use Python too.

One thing I don’t like about it is that when you put Blender into the background, Python scripts seem to go a lot slower. I don’t know if it switches to some lower CPU background mode or something.

V interesting, thanks.

Have you tried comparing it to numeric?

Thanks for the benchmark! - nice to know blender is faster :wink: in the big picture this might not be that big a difference since its hard to know how much these operations would effect real world cases. but still nice.

a few people have suggested we replace mathutils with numarray, but for now Im happy not to. especially since we can have funcs that are more spesific to 3d apps built in to the API…( I know, we could subclass numarray… :confused: and add our own funcs… but thats work isnt it!)


Actually, you can’t subclass numarray - it has the same problem as Blender. I started to wonder when I saw the note under the dot product function in numarray saying “somebody who knows something about matrix multiplication should really do this properly one of these days”. It may be really fast at higher-dimensional arrays, but its definately not optimized for matrices.

Actually, if you could really subclass Blender classes, its not a bad little graphics toolkit. With the exception of the gaming-oriented toolkits (Ogre, Crystal3d) which seem to be very poorly documented, there’s not much out there besides cgkit.