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 isNumber(num){
return (typeof num === 'number' && !isNaN(num));
}
function toFixed(value,precision, roundingMethod = 'round')
{
roundingMethod = roundingMethod.toLowerCase()
if(isNaN(precision)){
throw new Error("precision is NaN");
}
if(isNaN(value)){
throw new Error("value is NaN");
}
if(precision<0) precision = 0
let negative = (value<0);
value = Math.abs(value);
let fixer = Math.pow(10,precision);
if(roundingMethod == 'floor') value = Math.floor(value * fixer) / fixer;
else if(roundingMethod == 'ceil') value = Math.ceil(value * fixer) / fixer;
else value = Math.round(value * fixer) / fixer;
return (negative ? (-value) : value);
}
function findPrecisionStr(num) {
if (!isFinite(num)) return 0;
if (typeof num !== "number") num = +num;
if (isNaN(num)) return 0;
num = num.toString();
let afterDot = num.match(/\.(.+?)(?=e|$)/)
let afterE = num.match(/e[+-](.+)/)
afterDot = afterDot ? afterDot[1].length : 0
afterE = afterE ? +afterE[1] : 0
return (afterDot + afterE)
}
function randNum(min,max, precision = true)
{
if(isNaN(min) || isNaN(max))
{
throw new Error("min or max is NaN");
}
if(min == max) return max;
if(precision === true){
let minP = findPrecision(min)
let maxP = findPrecision(max)
if(minP==16.5) minP = 16;
if(maxP==16.5) maxP = 16;
precision = maxP > minP ? maxP : minP;
return toFixed(((Math.random() * ((max+1)-min)) + min), precision);
}
if(isNumber(precision)){
return toFixed(((Math.random() * ((max+1)-min)) + min), precision);
}
else{
return ((Math.random() * ((max+1)-min)) + min);
}
}
let opts = [
[1, 2, 2],
[0, 12, false],
[-8, 4, true],
[-1.34, 2.945, true],
[-20, -5, null],
[2.8, 0, 2],
[1.4858, 6.45, true],
[9.857203, 8.857203, 3],
[-2.3455, 2.3455, true],
[3.89, 3.456, 1],
[0, 0, true]
]
Ready to run.
Test | Ops/sec | |
---|---|---|
"Complex" rand num |
| ready |
Normal rand num |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.