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
function distance1(_a, _b, in_check) {
// https://discord.com/channels/238332476743745536/1025784763958693958
if (!_a || !_b) return 99999999;
if ("in" in _a && "in" in _b && _a.in != _b.in) return 99999999;
if ("map" in _a && "map" in _b && _a.map != _b.map) return 99999999;
const a_x = _a.x
const a_y = _a.y
const b_x = _b.x
const b_y = _b.y
const a_w2 = _a.width / 2
const a_h = _a.height
const b_w2 = _b.width / 2
const b_h = _b.height
// Check if they're just 2 points
if(a_w2 == 0 && a_h == 0 && b_w2 == 0 && b_h == 0) return Math.hypot(a_x - b_x, a_y - b_y)
// Check overlap
if ((a_x - a_w2) <= (b_x + b_w2)
&& (a_x + a_w2) >= (b_x - b_w2)
&& (a_y) >= (b_y - b_h)
&& (a_y - a_h) <= (b_y) ) return 0
// TODO: If one is just a single point, we're computing 8 needless calculations.
// Compare the 4 corners to each other
let min = 99999999
for(const a_c of [{ x: a_x + a_w2, y: a_y - a_h},
{ x: a_x + a_w2, y: a_y},
{ x: a_x - a_w2, y: a_y - a_h},
{ x: a_x - a_w2, y: a_y}]) {
for(const b_c of [{ x: b_x + b_w2, y: b_y - b_h},
{ x: b_x + b_w2, y: b_y},
{ x: b_x - b_w2, y: b_y - b_h},
{ x: b_x - b_w2, y: b_y}]) {
const d = Math.hypot(a_c.x - b_c.x, a_c.y - b_c.y)
if(d < min) min = d
}
}
return min
}
function distance2(_a, _b, in_check) {
// https://discord.com/channels/238332476743745536/1025784763958693958
if (!_a || !_b) return 99999999;
if ("in" in _a && "in" in _b && _a.in != _b.in) return 99999999;
if ("map" in _a && "map" in _b && _a.map != _b.map) return 99999999;
const a_x = _a.x
const a_y = _a.y
const b_x = _b.x
const b_y = _b.y
const a_w2 = _a.width / 2
const a_h = _a.height
const b_w2 = _b.width / 2
const b_h = _b.height
// Check if they're just 2 points
if(a_w2 == 0 && a_h == 0 && b_w2 == 0 && b_h == 0) return Math.hypot(a_x - b_x, a_y - b_y)
// Check overlap
if ((a_x - a_w2) <= (b_x + b_w2)
&& (a_x + a_w2) >= (b_x - b_w2)
&& (a_y) >= (b_y - b_h)
&& (a_y - a_h) <= (b_y) ) return 0
let min = 99999999;
let a_x1 = a_x + a_w2;
let a_x2 = a_x - a_w2;
let b_x1 = b_x + b_w2;
let b_x2 = b_x - b_w2;
let a_y1 = a_y;
let a_y2 = a_y - a_h;
let b_y1 = b_y;
let b_y2 = b_y - b_h;
let minX = Math.min(
Math.abs(a_x1 - b_x1),
Math.abs(a_x1 - b_x2),
Math.abs(a_x2 - b_x1),
Math.abs(a_x2 - b_x2)
);
let minY = Math.min(
Math.abs(a_y1 - b_y1),
Math.abs(a_y1 - b_y2),
Math.abs(a_y2 - b_y1),
Math.abs(a_y2 - b_y2)
);
return Math.hypot(minX, minY);
}
var CASES = new Array(100).fill(undefined).map(() => {
return [
{
x: Math.random() * 100,
y: Math.random() * 100,
width: Math.random() * 10,
height: Math.random() * 10
},
{
x: Math.random() * 100,
y: Math.random() * 100,
width: Math.random() * 10,
height: Math.random() * 10
}
];
});
var TOTAL1 = 0;
var TOTAL2 = 0;
Ready to run.
Test | Ops/sec | |
---|---|---|
Old Test |
| ready |
New Test |
| ready |
Sanity |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.