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
Jump 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
Test name
Executions per second
function declaration
79686.0 Ops/sec
function expression
79841.1 Ops/sec
class
79922.6 Ops/sec
Related benchmarks:
function vs class
function vs class 2
function vs class method vs new function method
function vs class method vs new function method v2
diff between func types
function vs class vs arrow function
function vs class 8
Class VS Function Benchmark Test
function vs class vs proto
Comments
Confirm delete:
Do you really want to delete benchmark?