Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object creation: arrow function vs. class with methods
Functions create a raw object, while class instances can rely on the prototype. Which one is faster?
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6.1 Safari/605.1.15
Browser:
Safari 17
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Create object by function
9883335.0 Ops/sec
Create object by class
1731881.6 Ops/sec
Tests:
Create object by function
const carFactory = (brand, seats) => ({ brand, seats, sound: () => console.log("wrooom") }) for(let i = 0; i < 20; i++) { carFactory(`brand-${i}`, 5) }
Create object by class
class Car { brand; seats; constructor(brand, seats) { this.brand = brand; this.seats = seats; } sound() { return console.log("wrooom") } } for(let i = 0; i < 20; i++) { new Car(`brand-${i}`, 5) }