CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 11-08-2013, 01:03 PM   #16
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,637
Send a message via ICQ to denisT
Quote:
Originally Posted by denisT
as i told, came from max, i use try statement with caution. for max c++ API it's almost nothing, but the using it in the maxscript causes noticeable slowing down.

the python as any other script...
Code:
t1 = cmds.timerX() v = 0 a = "1" for k in xrange(100000): if type(a) is int: v += 1 print ">> %s" % cmds.timerX(startTime = t1) ### >> 0.0300000000134 t1 = cmds.timerX() v = 0 a = "1" for k in xrange(100000): try: v += a except: pass print "<< %s" % cmds.timerX(startTime = t1) ### << 0.25
 
Old 11-08-2013, 01:27 PM   #17
haggi
Expert
3d freelancer
 
Join Date: Apr 2004
Posts: 1,064
Quote:
Originally Posted by denisT
i can use of course cmds.objExists but i don't like mix OpenMaya and cmds methods in one function.
thanks


May I ask you why you want to avoid the mix? Isn't this exaclty what the python api is made for?
__________________
www.renderwiki.com - www.openmaya.net
 
Old 11-08-2013, 02:00 PM   #18
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,637
Send a message via ICQ to denisT
Quote:
Originally Posted by haggi
May I ask you why you want to avoid the mix? Isn't this exaclty what the python api is made for?

there is nothing special about it. it's just my personal preference. i just don't have time right now to check every cmds command for performance. maybe the situation changed since last time i did it, but as i remember cmds commands were not fast.
 
Old 11-08-2013, 04:31 PM   #19
Keilun
Expert
Keilun
Canada
 
Join Date: Aug 2005
Posts: 738
I can understand not wanting to test performance in every case, but for the most part you should only need to investigate if you find there's a bottleneck that's holding you back. That said, there are cases where MEL commands are indeed faster than the Python API.

One case of this is the select command versus MSelectionList.add():

Assume I had a scene with 8000 spheres in it.

Code:
# TEST 000: maya.cmds.select import maya.cmds as cmds import time start = time.clock() objs = [] for i in xrange(1,8001): obj = "pSphere" + str(i) objs.append( obj ) cmds.select( objs ) end = time.clock() cmds.select( cl=True ) print end-start # 0.2


Code:
# TEST 001: MGlobal.setActiveSelectionList import maya.OpenMaya as om import time start = time.clock() selList = om.MSelectionList() for i in range(1,8001): obj = "pSphere" + str(i) selList.add( obj ) end = time.clock() print end-start om.MGlobal.setActiveSelectionList( selList ) end = time.clock() print end-start # 0.6


There are numerous ways to select in the API and I did test the others (selectByName, selectCommand, etc.) but they were slower. selectCommand was close to on par with the MSelectionList.add.

My test assumes 8000 uniquely named objects which is why I don't create a simple match string to find all those spheres which I'm sure would likely be faster than calling MSelectionList.add() 8000 times.. select via MEL is indeed faster than the Python API.

Last edited by Keilun : 11-08-2013 at 04:35 PM.
 
Old 11-08-2013, 05:47 PM   #20
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,637
Send a message via ICQ to denisT
add by pattern very slow. how many surprises...
Code:
t1 = cmds.timerX() list = OpenMaya.MSelectionList() list.add('pSphere*') list.length() print cmds.timerX(startTime = t1) # 3.37

i know it add the shapes as well, but who cares... in max it takes 0.012 sec

but the question... c++ API does do it fast, doesn't it? where is the bottleneck?
 
Old 11-08-2013, 05:57 PM   #21
Keilun
Expert
Keilun
Canada
 
Join Date: Aug 2005
Posts: 738
I haven't tested the C++ side.

I tested Python API 2.0 here and it's just as slow. The actual string matching process must be slow and the select command must be doing something differently to process it faster than MSelectionList, but I'm not sure what specifically that is.

Last edited by Keilun : 11-08-2013 at 06:01 PM.
 
Old 11-08-2013, 06:32 PM   #22
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,637
Send a message via ICQ to denisT
Quote:
Originally Posted by Keilun
There are numerous ways to select in the API and I did test the others (selectByName, selectCommand, etc.) but they were slower. selectCommand was close to on par with the MSelectionList.add.

Code:
t1 = cmds.timerX() list = OpenMaya.MItDependencyNodes(OpenMaya.MFn.kTransfor m) spheres = OpenMaya.MObjectArray() while not list.isDone(): node = list.thisNode() obj = OpenMaya.MFnDependencyNode(node) if "pSphere" in obj.name(): spheres.append(node) list.next() print cmds.timerX(startTime = t1) # 0.22 spheres.length()

0.22 sec ... not too bad
 
Old 11-11-2013, 03:19 PM   #23
uiron
neglostyti
 
uiron's Avatar
portfolio
Viktoras Makauskas
Lithuania
 
Join Date: Jun 2005
Posts: 615
Quote:
Originally Posted by denisT
i know how try statement works (c++, c#, python, maxscript, ...) but if you don't know the system very well it might hide from you the real reason of an exception. <....> try/catch statement is kinda last in list of solutions


I might be late to the discussion, but exception handling code is a first-class flow control form, just like an "if" or "for" blocks. Performance wise you won't get any real benefit, you'll just write "if exists then... " instead of "assume it exists, handle it if it goes wrong".

about hiding the reason of the exception... that's totally not true. exception handling gives great control of information why something failed, and how to control specific types of exceptional cases, like "if user supplied arguments were wrong, do this, and if we have unforseen internal problem during execution, do this".

Your story about whiskey is not how exception handling works, it's more how API that throws no error works - it fails, but does not report the problem. In exception handling case, it would be:

Code:
try: self.goToRestaurant() self.orderDrink() except OutOfStockException as e: print "damn, there was no stock of "+e.item self.tryOrderingSomethingElse() except IllegalAgeException as e: print "damn, I must be %s to order %s" % (e.legealAge,e.drinkType) except RestaurantPolicyException as e: print "I was not served because "+str(e) except BaseException as e: throw IllegalStateException("unforseen problems during restaurant visit: "+str(e))


.. so you can be as verbose as you'd like, maybe you only want to handle one situation, have a default handler for any exception, or rethrow for outside flow to handle. in fact, leaving exceptions for outer flow to handle is the most overlooked use case for those still trying to understand the real benefits of the system. Or catch - provide own implementation of recovery - rethrow for outer flow to handle it's own bit..

not using exception handling in your arsenal is one step away from not using.. don't know, objects and polymorphism, because you've heard that in this other language virtual function table is a lot of overhead! yes, it is, but it does not matter in Python
__________________
Victor
ngskintools.com - skinning plugin for Autodesk Maya
 
Old 11-11-2013, 03:19 PM   #24
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 09:30 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.