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
const asc = (a, b) => a - b;
export const alignSeries = (series) => {
const timestampsSet = new Set([...series.flatMap((item) => item.map((v) => v[0] / 1000))]);
const timestamps = Array.from(timestampsSet).sort(asc);
const seriesMaps = series.map((s) => new Map(s));
const alignedSeries = series.map(() => new Array(timestamps.length).fill(null));
// the scaleFactors array stores a scaling factor for each series
// to ensure that extremely large values (> Number.MAX_SAFE_INTEGER)
// are scaled down to avoid potential issues with js number precision limits
const scaleFactors = [];
for (let j = 0; j < series.length; j++) {
let maxSeriesValue = Number.NEGATIVE_INFINITY;
for (let i = 0; i < timestamps.length; i++) {
const ts = timestamps[i];
const v = seriesMaps[j].get(ts * 1000);
alignedSeries[j][i] = v ?? null;
maxSeriesValue = v && maxSeriesValue < v ? v : maxSeriesValue;
}
scaleFactors.push(maxSeriesValue > Number.MAX_SAFE_INTEGER ? 1e12 : 1);
}
return {
scaleFactors,
series: alignedSeries,
timestamps,
};
};
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| normal | | ready |
| more | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.