LoginSignup
6
6

More than 5 years have passed since last update.

Androidの標準ブラウザで使える簡単な処理時間計測スクリプト

Posted at

Androidの標準ブラウザでデバッグする時に困る事があるのは

console.log();
console.info();
console.warn();
console.error();

の上記functionしか使えない部分です。
で、ブラウザでデバッグする時に個人的に便利だなーって思ったのが

console.time();
console.timeEnd();

の二つのfunctionです。

なので、無ければ実装すれば良いじゃん、という事でconsole.log();を使って実装。

sensing.js
var K = (function() {
  var timeManager = {};
  return {
    /**
     * 計測開始
     * @param {String} label
     */
    timeStart: function(label) {
      timeManager[label] = (new Date()).getTime();
      console.log(label, "start sensing");
    },
    /**
     * 計測停止
     * @param {String} label
     */
    timeEnd: function(label) {
      console.log(label, (new Date()).getTime() - timeManager[label] + "ms");
      delete timeManager[label];
    }
  }
})();

使い方

使い方は至って簡単。
console.time();console.timeEnd();に同じ。
K.timeStart("func1");で開始。
K.timeEnd("func1"); // timeStartで渡した同じlabelを渡すで終了。
timeStartからtimeEndまでのmsを算出します。
精確な値を出すわけではないですが、簡単な処理計測をする等には楽です。

6
6
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
6
6