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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
function declaration
15020.9 Ops/sec
function expression
15410.7 Ops/sec
class
5161.5 Ops/sec
proto
5576.2 Ops/sec
Typescript Compiled
5522.9 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); }