Skip to content

Instantly share code, notes, and snippets.

@nrtkbb
Last active May 11, 2018 08:38
Show Gist options
  • Save nrtkbb/74cccb17f6c76404e4dcafdd8389b604 to your computer and use it in GitHub Desktop.
Save nrtkbb/74cccb17f6c76404e4dcafdd8389b604 to your computer and use it in GitHub Desktop.
cmds.nodeType vs cmds.ls(type=)
node_list = cmds.ls()
print(node_list)
# Result: 9044
start = datetime.datetime.now()
for i in xrange(100):
shading_engine = cmds.ls(type='shadingEngine')
if not shading_engine:
continue
found = False
for node in node_list:
if node in shading_engine:
found = True
break
if found:
pass
print(datetime.datetime.now() - start)
# Result: 0:00:00.082000
start = datetime.datetime.now()
for i in xrange(100):
shading_engine = cmds.ls(type='shadingEngine')
if not shading_engine:
continue
found = False
for sg in shading_engine:
if sg in node_list:
found = True
break
if found:
pass
print(datetime.datetime.now() - start)
# Result: 0:00:00.101000
start = datetime.datetime.now()
for i in xrange(100):
shading_engine = cmds.ls(type='shadingEngine')
if not shading_engine:
continue
shading_engine_set = set(shading_engine)
node_set = set(node_list)
if shading_engine_set & node_set:
pass
else:
pass
print(datetime.datetime.now() - start)
# Result: 0:00:00.129000
from maya import cmds
import datetime
start = datetime.datetime.now()
for i in xrange(100):
node_types = [cmds.nodeType(l) for l in node_list]
if 'shadingEngine' in node_types:
pass
else:
pass
print(datetime.datetime.now() - start)
# Result: 0:00:07.147000
start = datetime.datetime.now()
for i in xrange(100):
node_types = {cmds.nodeType(l):True for l in node_list}
if 'shadingEngine' in node_types:
pass
else:
pass
print(datetime.datetime.now() - start)
# Result: 0:00:07.086000
start = datetime.datetime.now()
for i in xrange(100):
if cmds.ls(node_list, type='shadingEngine'):
pass
else:
pass
print(datetime.datetime.now() - start)
# Result: 0:00:04.859000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment