LoginSignup
8
7

More than 5 years have passed since last update.

メソッドごとにパフォーマンスを計測したい

Posted at

思ったよりも簡単です。やり方はFunction.prototype.applyを使ってあるメソッドの実行をhookするだけです。

js

function calcPerf (tag, tgt, func, args) {
    tgt = tgt || this;
    args = args || [];
    var n = performance.now();
    func.apply(tgt, args);
    var t = performance.now() - n;
    if ( t > 16 ) {
        // over 60fps
        console.warn(tag+": takes "+t+" ms!";
    }
}

js

calcPerf("drawSome", that, that.prototype.drawSome, [flag]);

こうすることで16ms以上かかったメソッドの実行を検出することができます。問題は実行するfuncの中のどの部分がheavyなのかは分かないという点ですが。

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7