Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
objct vs function vs class
(version: 1)
Comparing performance of:
function vs object vs object with extern method vs class
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
pr=function(){ let a=0; this.add=()=>{ a+=1; } }; const pro={ a:0, add(){ const $=this; $.a+=1; } }; const pro2=Object.assign({},pro); pro2.add2=function(){ const $=this; $.a+=1; }; class Pr { constructor() { this.a = 0; } add() { this.a += 1; } } let c=0;
Tests:
function
k = new pr(); for(c=0;c<1000;c++){ k.add(); }
object
const ob=Object.assign({},pro); for(c=0;c<1000;c++){ ob.add(); }
object with extern method
const ob2=Object.assign({},pro2); for(c=0;c<1000;c++){ ob2.add2(); }
class
j=new Pr(); for(c=0;c<1000;c++){ j.add(); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
function
object
object with extern method
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
function
8246.3 Ops/sec
object
9476.8 Ops/sec
object with extern method
9406.3 Ops/sec
class
8613.3 Ops/sec
Related benchmarks:
prototype function
Is plain object
object creation: new, object.create, literal+proto
object creation+method lookup: new, object.create, literal+proto
object mixin compare
class vs function constructor vs object literal vs __proto__ vs Object.create vs Object.setPrototypeOf
objct vs function
objct1 vs function1
objct3 vs function3
Comments
Confirm delete:
Do you really want to delete benchmark?