jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
class Shape2D {
width
height
constructor(w, h) {
this.width = w
this.height = h
}
calculateArea() {
throw new Error("calculateArea function is not implemented!")
}
}
class Triangle extends Shape2D {
calculateArea() {
return (this.width * this.height) / 2
}
}
class Square extends Shape2D {
calculateArea() {
return this.width * this.width
}
}
const triangle = new Triangle(10, 10)
const square = new Square(10)
function sumAllShapes(shapes) {
let total = 0
for(const shape of shapes) {
total += shape.calculateArea()
}
return total
}
const shapes = [triangle, square, triangle, square, triangle, square, triangle, square]
//////////
const triangleObj = { width: 10, height: 10 }
const squareObj = { width: 10, height: 0 }
function calculateAreaTriangle(shape) {
return (shape.width * shape.height) / 2
}
function calculateAreaSquare(shape) {
return shape.width * shape.width
}
function sumAllShapesObj(shapes) {
let total = 0
for (const shape of shapes) {
if(shape.height == 0) {
total += calculateAreaSquare(shape)
} else {
total += calculateAreaTriangle(shape)
}
}
return total
}
const shapesObj = [triangleObj, squareObj, triangleObj, squareObj, triangleObj, squareObj, triangleObj, squareObj]
Ready to run.
Test | Ops/sec | |
---|---|---|
OOP |
| ready |
PROCEDURAL |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.