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 = (object, ...rest) => {
let key = dispatch(object, ...rest)
let method = methods.get(key)
return method(object, ...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(x => x.type)
add.define(
'vec2d',
(object, x, y) => ({
type: 'vec2d',
x: object.x + x,
y: object.y + y
})
)
let origin = {
type: 'vec2d',
x: 0,
y: 0
}
let originCoords = new Coords(0, 0)
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.