optimizing code, unusual results

29 views
Skip to first unread message

s...@weacceptyou.com

unread,
Nov 4, 2015, 9:47:25 AM11/4/15
to Python Programming for Autodesk Maya
Hi,

im trying to make my script as efficient as possible. I have placed all these lines in my code to see how fast different sections are running and then just focusing on those areas.

###########################
t0 = time.clock()

print time.clock() - t0
###########################

The problem is certain areas seem to take a long time when they have no need to.

there is a loop in my script that just finds four points in space:
pnt1=cmds.pointPosition('curve5.ep[2]') pnt2=cmds.pointPosition('curve5.ep[4]') pnt3=cmds.pointPosition('curve5.ep[5]') pnt4=cmds.pointPosition('curve5.ep[6]')

but the very first time the first line is called, the program takes 0.5 seconds to complete, but then every time it loops through again it takes 0.0001 seconds to complete. Can anyone explain why this might be. really confusing. I presume it maybe loading curve into memory or something? dunno

thanks,
Sam

yury nedelin

unread,
Nov 4, 2015, 9:52:40 AM11/4/15
to python_in...@googlegroups.com

Try looking up python cprofiler.
Yury

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e7373880-cf36-4835-ad81-ca5d9d6e31fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ravi Jagannadhan

unread,
Nov 4, 2015, 10:25:43 AM11/4/15
to python_in...@googlegroups.com
One test you can try is doing your second set of lines on a different shape. Then you'd know for sure if it's caching anything.

"There are no dumb questions" - Carl Sagan.

Justin Israel

unread,
Nov 4, 2015, 12:17:57 PM11/4/15
to Python Programming for Autodesk Maya

http://www.huyng.com/posts/python-performance-analysis/

The line profiler would make this a lot easier for you to profile. Just decorate the desired function with @profile
No imports needed.
Then run it with kernprof.py and the desired flags.

For simple calls into the Maya commands, it would be hard to know what the implementation is doing. It very well could be loading a larger data structure the first time, and then hitting a cache for subsequent calls.


s...@weacceptyou.com

unread,
Nov 4, 2015, 3:34:22 PM11/4/15
to Python Programming for Autodesk Maya
thanks guys, will check this out. want to get my code as fast as poss!

cheers,
Sam
Reply all
Reply to author
Forward
0 new messages