Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
function vs class with external declarations
(version: 1)
Comparing performance of:
function declaration vs function expression vs class
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
var arr = 1 var functionExpression = function(item) { arr = item }; function functionDeclaration(item) { arr = item } class Test { constructor() { } addItem(item){ arr = item } } var _test = new Test() function functionClass(item) { _test.addItem(item); }
Tests:
function declaration
arr =2 for (let i = 1; i < 10000; i++) { functionDeclaration(i); }
function expression
arr =1 for (let i = 1; i < 10000; i++) { functionExpression(i); }
class
arr =1 for (let i = 1; i < 10000; i++) { _test.addItem(i); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
function declaration
function expression
class
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
Browser/OS:
Chrome 132 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
class
80K/s
function expression
80K/s
function declaration
80K/s
View exact numbers
Test name
Executions per second
✓
class
79,923 Ops/sec
function expression
79,841 Ops/sec
function declaration
79,686 Ops/sec
Related benchmarks
function vs class
function vs class method vs new function method
function vs class method vs new function method v2
function vs class vs proto
Comments
Confirm delete:
Do you really want to delete benchmark?