Performance comparison: MEL vs PyMel vs OpenMaya vs maya

Friday, 17 August 2012

Performance comparison: MEL vs PyMel vs OpenMaya vs maya.cmds vs C++

Over the years Maya has grown to have quite the myriad of programming APIs. MEL and the C++ API have been joined by Python maya.cmds, the OpenMaya Python API wrapper and PyMel. Now I read Maya 2013 is getting Python API 2.0. I've read a lot of discussion on what's quickest but most of them are based on generic assumptions (simpler is quicker so PyMel must be slowest) and don't quote any specific timings. So I've done some myself, while profiling tools and trying to get the most performance out of them. (All timings are in seconds)
Example: having selected 10000 edges, convert the selection to faces.
PyMel:1.7
maya.cmds:7.5
MEL:7.4
OpenMaya:0.2

OpenMaya is quickest by far, but PyMel is still 4.5x faster then MEL or maya.cmds. What will slow it down however, is if we add a small change - flattening the selection list (i.e.: "ls -sl -fl"):
Timings with selection list flattening:
PyMel:7.9
maya.cmds:8.0
MEL:7.7
OpenMaya:0.2 (there is no distinction in the API, same code)

Here it's roughly the same speed as MEL and maya.cmds. What seems to slow it down is creating instances of PyMel classes as we will see in the next example.
Example: custom edge ring select:
PyMel:2.4
maya.cmds:1.2
OpenMaya:0.03

PyMel stumbles here, maya.cmds is quicker but OpenMaya turns out nearly 40x faster still. However it's interesting to note that a lot of the PyMel code actually runs 2 or 3 times faster then the maya.cmds code. What slows it down is one part of it, which creates PyMel objects. To be clear, by creating PyMel objects, I mean something like: edge = pymel.core.general.MeshEdge( someMesh, someEdgeIndex ).

The overall conclusion I can draw is that PyMel is quick. A lot of it builds on top of OpenMaya, which is the quickest of all the scripting APIs. Maya.cmds is really just a thin wrapper on top of MEL, and there is no significant performance difference between the two. As long as you can avoid creating a lot of PyMel objects in your code, you should find it outperforming both maya.cmds and MEL.

We know OpenMaya is very quick, but lets compare it to it's non interpreted, compiled flavour: the C++ API. I have a simple plugin deformer implemented in both C++ and Python. It basically takes a point on a curve, calculates a normal to the curve at that point and then bends geometry along that curve. The timings are:

Python
Finding the point along the curve:0.027
Calculating a normal:0.15
Deforming passed points:0.060

C++
Finding the point along the curve:0.017
Calculating a normal:0.0023
Deforming passed points:0.000062

"Finding the point along the curve" is a single function call and most of the work gets done by Maya. There is only a small difference between Python and C++. "Deforming passed points" however, is a bunch of adding and multiplying. No API function gets called. Here C++ outperforms Python by nearly a thousand-fold. The more I work on this plugin the more dramatic the overall difference becomes. For deformers at least, C++ is massively quicker then Python.

These tests are only very limited, I admit, but the medal standings are: gold for C++, silver for OpenMaya, and bronze for PyMel. MEL and maya.cmds are tied for a close fourth.
Posted by ElDonaldo  at 04:11 


性能比较:MEL vs PyMel vs OpenMaya vs maya.cmds vs C ++

多年以来,maya已经有了很多编程API。MEL和C ++ API已经由Python maya.cmds,OpenMaya Python API包装器和PyMel加入。现在我看到Maya 2013正在获得Python API 2.0。我已经阅读了很多有关最快速度的讨论,但大多数都是基于通用的假设(更简单,因此PyMel必须最慢),并且不引用任何具体的时间。所以我做了一些自己,在分析工具,并试图获得最好的表现。(所有时间以秒为单位)
示例:选择10000个边,将选择转换为面。
PyMel:1.7
maya.cmds:7.5
MEL:7.4
OpenMaya:0.2

OpenMaya到目前为止最快,但是PyMel比MEL还是maya.cmds还要快4.5倍。然而,如果我们添加一个小的变化 - 将选择列表变平(例如:“ls -sl -fl”):
选择列表展平的时间:
PyMel:7.9
maya.cmds:8
MEL:7.7
OpenMaya:0.2(API中没有区别,代码相同)

这里与MEL和maya.cmds的速度大致相同。似乎减慢它的是创建PyMel类的实例,我们将在下一个例子中看到。
示例:定制边缘选择:
PyMel:2.4
maya.cmds:1.2
OpenMaya:0.03

PyMel在这里磕磕绊绊,maya.cmds更快,但OpenMaya的速度仍然快了近40倍。但是有趣的是,PyMel代码实际上运行速度比maya.cmds代码快2到3倍。减慢它的一部分,它创建PyMel对象。要清楚,通过创建PyMel对象,我的意思是:edge = pymel.core.general.MeshEdge(someMesh,someEdgeIndex)。

我可以得出的总体结论是PyMel很快。其中很多建立在OpenMaya之上,这是所有脚本API中最快的。Maya.cmds真的只是MEL之上的薄薄包装,两者之间没有显着的性能差异。只要您可以避免在代码中创建大量PyMel对象,那么您应该发现它的性能优于maya.cmds和MEL。

我们知道OpenMaya是非常快速的,但是将其与未解释的编译风格进行比较:C ++ API。我有一个简单的插件变形器实现在C ++和Python。它基本上需要一个曲线上的点,计算该点上的曲线的法线,然后沿该曲线弯曲几何。时间是:

Python
找到曲线上的点:0.027
计算正常:0.15
变形通过点:0.060

C ++
找到曲线上的点:0.017
计算正常:0.0023
变形通过点:0.000062

“找到曲线点”是一个单一的函数调用,大部分工作都是由Maya完成的。Python和C ++之间只有很小的区别。然而,“变形通过点”是一系列增加和增加。没有API函数被调用。这里的C ++比Python好几十倍。我在这个插件上工作的越多,整体差异越大。至少对于变形器,C ++比Python快很多。

这些测试只是非常有限,我承认,但是奖牌排名是:C ++的金,OpenMaya的银,PyMel的青铜。MEL和maya.cmds绑在第四位。
发贴者 ElDonaldo 在 4时11分 












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值