Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Constructor parameters versus object assignment
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Constructor parameters
271.1 Ops/sec
Constructor object
82.4 Ops/sec
Factory function with object
212.5 Ops/sec
Factory function with definition and parameters
226.5 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ async function globalMeasureThatScriptPrepareFunction() { // This function is optional, feel free to remove it. // await someThing(); }
Tests:
Constructor parameters
class Component { constructor(x, y) { this.x = x; this.y = y; } } for(let i = 0; i < 100000; i++) { const component = new Component(i, i); }
Constructor object
class Component { constructor(params) { const keys = Object.keys(params); for(let i = 0, l = keys.length; i < l; i++) { this[keys[i]] = params[i]; } } } for(let i = 0; i < 100000; i++) { const component = new Component({ x: i, y: i}); }
Factory function with object
const createComponent = (params) => { const component = {}; const keys = Object.keys(params); for(let i = 0, l = keys.length; i < l; i++) { component[keys[i]] = params[i]; } return component; } for(let i = 0; i < 100000; i++) { const component = createComponent({ x: i, y: i}); }
Factory function with definition and parameters
const positionComponentDef = { x: Number, y: Number, }; const createComponent= (def, ...params) => { const component = {}; const keys = Object.keys(def); for(let i = 0, l = keys.length; i < l; i++) { component[keys[i]] = params[i]; } return component; } for(let i = 0; i < 100000; i++) { const component = createComponent(positionComponentDef, i, i); }