Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active April 25, 2017 03:25
Show Gist options
  • Save patwooky/1b34c1a301ead22fe7e294702e8f57bd to your computer and use it in GitHub Desktop.
Save patwooky/1b34c1a301ead22fe7e294702e8f57bd to your computer and use it in GitHub Desktop.
a function to compare a time taken to perform similar set of actions using maya.cmds and pymel.
'''
a function to compare a time taken to perform similar
set of actions using maya.cmds and pymel.
original code taken from:
http://www.macaronikazoo.com/?p=271
'''
import time
import maya.cmds as mc
from pymel.core import *
def testMayaCmdsPymel(numIterList):
'''
a function to compare a time taken to perform similar
set of actions using maya.cmds and pymel.
numIterList - a list consisting of the number of iterations
which to run the comparison tests on
'''
def testCmds(numIter):
MAX = numIter
start = time.clock()
objList = []
print '-- maya.cmds --'
for n in xrange( MAX ):
obj = mc.polyCube()[0]
objList.append(mc.rename(obj, 'cube1'))
mc.ls()
mc.delete(objList)
timeCmds = time.clock()-start
print 'time taken %0.3f' % (timeCmds)
return timeCmds
def testPymel(numIter):
MAX = numIter
start = time.clock()
objList = []
print '-- pymel --'
for n in xrange( MAX ):
# using pymel’s wrapping of the polyCube() command
obj = polyCube()[0]
# using pymel's wrapping of rename() command
objList.append(rename(obj.name(), 'cube1'))
ls() # using pymel’s wrapping of the ls() command
delete(objList) # using pymel’s wrapping of the delete() command
timePymel = time.clock()-start
print 'time taken %0.3f' % (timePymel)
return timePymel
timeDiffDict = {}
mainStart = time.clock()
for x in numIterList:
print 'duplicating %i objects' % (x)
timeCmds = testCmds(x)
timePymel = testPymel(x)
timeDiff = float(timePymel)/float(timeCmds)
timeDiffDict[x] = [timeCmds, timePymel, timeDiff]
print 'difference: %0.3f times\n' % (timeDiff)
print 'Results of test series:'
print 'num iterations\ttime cmds\ttime pymel\ttime difference'
print '--------------\t---------\t----------\t---------------\t'
for x in sorted(timeDiffDict.keys()):
print '%04i objects\t\t%0.3f s\t\t%0.3f s\t\t%0.3f times' % \
(x, timeDiffDict[x][0], timeDiffDict[x][1], timeDiffDict[x][2])
print '\ntotal time taken:', time.clock()-mainStart
testMayaCmdsPymel([10, 50, 100, 200, 300, 400, 500, 1000])
# testMayaCmdsPymel([10, 15, 20])
'''
-- sample output --
testMayaCmdsPymel([10, 50, 100, 200, 300, 400, 500, 1000])
duplicating 10 objects
-- maya.cmds --
time taken 0.078
-- pymel --
time taken 0.847
difference: 10.830 times
duplicating 50 objects
-- maya.cmds --
time taken 0.286
-- pymel --
time taken 4.359
difference: 15.220 times
duplicating 100 objects
-- maya.cmds --
time taken 0.660
-- pymel --
time taken 8.843
difference: 13.402 times
duplicating 200 objects
-- maya.cmds --
time taken 1.232
-- pymel --
time taken 20.434
difference: 16.588 times
duplicating 300 objects
-- maya.cmds --
time taken 1.773
-- pymel --
time taken 33.780
difference: 19.049 times
duplicating 400 objects
-- maya.cmds --
time taken 2.513
-- pymel --
time taken 49.537
difference: 19.713 times
duplicating 500 objects
-- maya.cmds --
time taken 3.159
-- pymel --
time taken 64.779
difference: 20.506 times
duplicating 1000 objects
-- maya.cmds --
time taken 7.550
-- pymel --
time taken 185.286
difference: 24.540 times
Results of test series:
num iterations time cmds time pymel time difference
-------------- --------- ---------- ---------------
010 objects 0.078 s 0.847 s 10.830 times
050 objects 0.286 s 4.359 s 15.220 times
100 objects 0.660 s 8.843 s 13.402 times
200 objects 1.232 s 20.434 s 16.588 times
300 objects 1.773 s 33.780 s 19.049 times
400 objects 2.513 s 49.537 s 19.713 times
500 objects 3.159 s 64.779 s 20.506 times
1000 objects 7.550 s 185.286 s 24.540 times
total time taken: 385.181002134
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment