Object Creation

JavaScript performance comparison

Test case created by JC Fant

Preparation code

<script>
  function ClosurePattern() {
   this.someMethod = function someMethod() {
    console.log('foo');
   }
  }
  
  function PrototypalPattern() {}
  PrototypalPattern.prototype = {
   someMethod: function() {
    console.log('foo');
   }
  }
  
  function sm() {
   console.log("foo")
  }
  
  function PrototypalWithHoisting() {}
  PrototypalWithHoisting.prototype = {
   someMethod: sm
  }
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Closure Pattern
var closurePattern = new ClosurePattern();
pending…
Prototypal Pattern
var prototypalPattern = new PrototypalPattern();
pending…
Prototypal Hoisting Pattern
var prototypalWithHoisting = new PrototypalWithHoisting();
pending…

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

Compare results of other browsers

0 Comments