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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Constructor parameters
685.1 Ops/sec
Constructor object
364.7 Ops/sec
Factory function with object
300.4 Ops/sec
Factory function with definition and parameters
316.6 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); }