Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Class method versus factory manager
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15
Browser:
Safari 15
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Class method
4393.5 Ops/sec
Factory manager
1118.0 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:
Class method
class TransformComponent { constructor(scaleX = 1.0, scaleY = 1.0, rotation = 0.0) { this.scaleX = scaleX; this.scaleY = scaleY; this.rotation = rotation; } scale(factor = 1.0) { this.scaleX *= factor; this.scaleY *= factor; } }; for(let i = 0; i < 10000; i++) { const transform = new TransformComponent(i, i, i); transform.scale(2.0); }
Factory manager
const components = new Map; const noop = () => {}; const componentsMethodCaller = (factory, methodName, ...values) => { const methods = components.get(factory); return (methods[methodName] || noop).apply(null, values); } const transformFactory = (scaleX = 1.0, scaleY = 1.0, rotation = 0.0) => { return { scaleX, scaleY, rotation, }; } components.set(transformFactory, { scale(component, factor = 1.0) { component.scaleX *= factor; component.scaleY *= factor; }, }); for(let i = 0; i < 10000; i++) { const transform = transformFactory(i, i, i); componentsMethodCaller(transformFactory, 'scale', 2.0); }