Plain vs custom object creation

JavaScript performance comparison

Test case created by Sam

Info

See this test.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var custom = function custom() {};
    var customWithProto = function customWithProto() {};
    customWithProto.prototype = {};
    var b = true;
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Plain
var obj = {};
b = !b || !!obj;
pending…
Plain (constructor)
var obj = new Object();
b = !b || !!obj;
pending…
Plain (with a property)
var obj = { __flag: true };
b = !b || !!obj;
pending…
Plain (with defineProperty)
var obj = {};
Object.defineProperty(obj, '__flag', { writable: false, value: true });
b = !b || !!obj;
pending…
Custom
var obj = new custom();
b = !b || !!obj;
pending…
Custom (with a proto)
var obj = new customWithProto();
b = !b || !!obj;
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

Add a comment