Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
function vs class vs proto
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
function declaration
8594.8 Ops/sec
function expression
10075.5 Ops/sec
class
10008.4 Ops/sec
proto
9202.4 Ops/sec
Typescript Compiled
9954.7 Ops/sec
Script Preparation code:
var arr = [];
Tests:
function declaration
arr = [] function functionDeclaration(item) { arr.push(item); } for (var i = 1; i < 10000; i++) { functionDeclaration(i); }
function expression
arr = [] var functionExpression = function(item) { arr.push(item); }; for (var i = 1; i < 10000; i++) { functionExpression(i); }
class
arr = [] class Test { constructor(a) { this.a = a; } addItem(item){ this.a.push(item) } } const t = new Test(arr); for (var i = 1; i < 10000; i++) { t.addItem(i); }
proto
arr = [] function ProtoTest(a) { this.arr = a } ProtoTest.prototype.addItem = function(item) { this.arr.push(item) } var t = new ProtoTest(arr); for (var i = 1; i < 10000; i++) { t.addItem(i); }
Typescript Compiled
arr = [] var TsTest = (function () { function TsTest(a) { this.arr = a; } TsTest.prototype.addItem = function (i) { this.arr.push(i); }; return TsTest; }()); var t = new TsTest(arr); for (var i = 1; i < 10000; i++) { t.addItem(i); }