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
Clojure-style multimethod
const multimethod = dispatch => {
const methods = new Map()
const func = (...rest) => {
let key = dispatch(...rest)
let method = methods.get(key)
return method(...rest)
}
func.define = (key, method) => {
methods.set(key, method)
}
return func
}
class Coords {
constructor(x, y) {
this.x = x
this.y = y
}
add(x, y) {
return new Coords(
this.x + x,
this.y + y
)
}
}
const add = multimethod(
(a, b) => `${a.type}-${b.type}`
)
add.define(
'v2d-v2d',
(a, b) => v2d(
a.x + b.x,
a.y + b.y
)
)
const v2d = (x, y) => ({type: 'v2d', x, y})
let origin = v2d(0, 0)
let originCoords = new Coords(0, 0)
let offsetCoords = v2d(5, -5)
Ready to run.
Test | Ops/sec | |
---|---|---|
multimethod |
| ready |
vanilla method |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.