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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
function declaration
1885.3 Ops/sec
function expression
1864.9 Ops/sec
class
12593.6 Ops/sec
proto
12513.0 Ops/sec
Typescript Compiled
12028.8 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); }