Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成したアトリビュートオブジェクトをキャッシュする #5

Closed
utatsuya opened this issue Mar 28, 2017 · 1 comment

Comments

@utatsuya
Copy link
Owner

アクセスの度にアトリビュートオブジェクトが生成されているので、呼び出しが多いほど無駄になる。
一度生成したら辞書としてキャッシュし、次回からはキャッシュから取り出して利用する。

@utatsuya
Copy link
Owner Author

utatsuya commented Apr 7, 2017

デフォルトでキャッシュが有効。MetanObject._cache = False にすることでキャッシュを無効化

import pymel.core as pm
import metan.debug as dbg
import metan.core as mtn

m1 = mtn.M("pCube1")
m1._cache = True # default:True
m2 = mtn.M("pCube1")
m2._cache = False
p = pm.PyNode("pCube1")


def func(m):m.tx;m.ty;m.tz
print dbg.run_profile(func, count=10000)(m1)  # 0.116s # metan cache:ON
print dbg.run_profile(func, count=10000)(m2)  # 1.636s # metan cache:OFF
print dbg.run_profile(func, count=10000)(p)  # 2.863s # pymel

def func1(m):m.t.tx;m.t.ty;m.t.tz
print dbg.run_profile(func1, count=10000)(m1)  # 0.164s # metan cache:ON
print dbg.run_profile(func1, count=10000)(m2)  # 3.504s # metan cache:OFF
print dbg.run_profile(func1, count=10000)(p)  # 4.755s # pymel

def func2(m):m.attr("tx");m.attr("ty");m.attr("tz")
print dbg.run_profile(func2, count=10000)(m1)  # 0.113s # metan cache:ON
print dbg.run_profile(func2, count=10000)(m2)  # 1.592s # metan cache:OFF
print dbg.run_profile(func2, count=10000)(p)  # 2.496s # pymel

def func3(m):m.attr("wm[0]")
print dbg.run_profile(func3, count=10000)(m1)  # 0.034s # metan cache:ON
print dbg.run_profile(func3, count=10000)(m2)  # 0.609s # metan cache:OFF
print dbg.run_profile(func3, count=10000)(p)  # 7.817s # pymel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant