[Bf-python] Transforming a mesh C-, amazing speed increase of exporters.

Jonathan Merritt j.merritt at pgrad.unimelb.edu.au
Sat Feb 5 22:18:02 CET 2005


Hi Campbell,

Campbell J Barton wrote:

><snip/>
>
>Transforming with mesh.transform(matrix)
>  Seconds: 0.0844249725342
>Transforming with Mathutils VecMultiMat, resizing the vert to a 4d vec, all in a
>for loop per vert. ..(Previously the best way???)
>  Seconds:   3.55111908913
>  
>

Just out of interest, is it any quicker to use map() or list 
comprehensions than a for loop in this case?

For map(), maybe something like this:

Mathutils.Matrix M
new_verts = map(lambda v: Mathutils.VecMultMat(v, M), verts)

and using list comprehensions:

Mathutils.Matrix M
new_verts = [ Mathutils.VecMultMat(v, M) for v in verts ]

I'd just be curious to know if either are faster than an "external" (or whatever you want to call it :-) for loop in this case.  The use of map() is a recommended way to speed up for loops (see the FAQ on www.python.org), but I'm not sure if the penalty of having the extra lambda function in there will offset any benefit.

Hmmm... time to go and do some testing for myself too, I think... :-)

-- 
Jonathan Merritt BE(Mech)/BSc
PhD Student - Equine Biomechanics
The University of Melbourne
Veterinary Clinical Centre, Werribee




More information about the Bf-python mailing list