Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
function vs class method vs new function method
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
pure function
382.6 Ops/sec
class method
168.2 Ops/sec
function method
11.4 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
for (var i = 0; i < numInstances; i++) { addItem(i); }
class method
for (var i = 0; i < numInstances; i++) { classInstances[i].addItem(i); }
function method
for (var i = 0; i < numInstances; i++) { functionInstances[i].addItem(i); }