Skip to content

Instantly share code, notes, and snippets.

@uhop
Created August 14, 2012 15:48
Show Gist options
  • Save uhop/3350415 to your computer and use it in GitHub Desktop.
Save uhop/3350415 to your computer and use it in GitHub Desktop.
Benchmarking creating an object
// 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"); }
);
@uhop
Copy link
Author

uhop commented Aug 14, 2012

Benchmark it with http://www.perfjs.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment