module vs prototype

Benchmark created by nwr on


Description

モジュールパターンとプロトタイプパターンで クラスを生成し比較します

Test runner

Ready to run.

Testing in
TestOps/sec
Module pettern
var Hoge = function(n) {

  function init() {
    var fuga = [];
    for (var i = 0; i <= 100; i++) {
      fuga.push(i * n);
    }
  }

  init();
}

for (var i = 0; i <= 400; i++) {
  Hoge(i);
}
ready
Prototype pettern
var Hoge = function(n) {
  this.init(n);
}
Hoge.prototype.init = function(n) {
  var fuga = [];
  for (var i = 0; i <= 100; i++) {
    fuga.push(i * n);
  }
}

for (var i = 0; i <= 400; i++) {
  new Hoge(i);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.