Created
August 14, 2012 15:48
-
-
Save uhop/3350415 to your computer and use it in GitHub Desktop.
Benchmarking creating an object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating different objects. | |
var z = 5; | |
this.group( | |
"Primitives", | |
function Nothing(x) { return; }, | |
function Null(x) { return null; }, | |
function Boolean(x) { return true; }, | |
function Number(x) { return 1; }, | |
function String(x) { return ""; }, | |
function VarArg(x) { return x; }, | |
function VarExt(x) { return z; } | |
); | |
this.group( | |
"Simple objects", | |
function Object(x) { return {}; }, | |
function Array(x) { return []; }, | |
function Function(x) { return function(){}; } | |
); | |
this.group( | |
"Complex objects", | |
function MObject(x) { return {a: 1, b: 2, c: 3}; }, | |
function MArray(x) { return [1, 2, 3]; }, | |
function MFunction(x) { return function(a, b, c){ return a + b + c; }; }, | |
function Closure(x) { return function(a){ return a + x + z; }; } | |
); | |
this.group( | |
"Builtin objects", | |
function DateObj(x) { return new Date; }, | |
function RegExpIn(x) { return /\s+\w/; }, | |
function RegExpEx(x) { return new RegExp("\s+\w"); } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmark it with http://www.perfjs.com/