Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
function vs class method vs new function method v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Goanna/6.8 Firefox/128.0 PaleMoon/33.9.1
Browser:
Pale Moon (Firefox Variant) 33
Operating system:
Windows
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
pure function
561.6 Ops/sec
class method
196.0 Ops/sec
function method
201.6 Ops/sec
Script Preparation code:
var arr = []; var classInstances = []; var functionInstances = []; var numInstances = 100000; function addItem(item) { arr.push(item); }; class TestClass { constructor() { } addItem(item){ this.item = item; arr.push(this.item) } } function TestFunction() { } TestFunction.prototype.addItem = function(item) { this.item = item; arr.push(item) } for( var i = 0; i < numInstances; i++ ) { classInstances[i] = new TestClass(); functionInstances[i] = new TestFunction(); }
Tests:
pure function
arr.length = 0; for (var i = 0; i < numInstances; i++) { addItem(i); }
class method
arr.length = 0; for (var i = 0; i < numInstances; i++) { classInstances[i].addItem(i); }
function method
arr.length = 0; for (var i = 0; i < numInstances; i++) { functionInstances[i].addItem(i); }