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
var valueFromPxPositionLookupHash = {},
valueFromPxPositionLookup = {},
valueFromPxPositionLookupMap = {};
var populateValueFromPxPositionLookupHash = function() {
valueFromPxPositionLookupHash = {};
var min = 50,
max = 1000,
step = 1,
width = 300;
for (var i=0;i<=width; i++) {
var hash = i + '-' + min + '-' + max + '-' + step + '-' + width;
var value = Math.round(
(min + (i / width) * (max - min)) / step
) * step;
if (value < min) {
value = min;
} else if (value > max) {
value = max;
}
valueFromPxPositionLookup[hash] = value;
}
};
var populateValueFromPxPositionLookup = function() {
valueFromPxPositionLookup = {};
var min = 50,
max = 1000,
step = 1,
width = 300;
for (var i=0;i<=width; i++) {
var value = Math.round(
(min + (i / width) * (max - min)) / step
) * step;
if (value < min) {
value = min;
} else if (value > max) {
value = max;
}
valueFromPxPositionLookup[i] = value;
}
};
var populateValueFromPxPositionMap = function() {
valueFromPxPositionLookupMap = {};
var min = 50,
max = 1000,
step = 1,
width = 300;
for (var i=0;i<=width; i++) {
var pxPosition = i;
var value = Math.round(
(min + (i / width) * (max - min)) / step
) * step;
if (value < min) {
value = min;
} else if (value > max) {
value = max;
}
if (valueFromPxPositionLookupMap[width] === undefined) {
valueFromPxPositionLookupMap[width] = {};
}
if (valueFromPxPositionLookupMap[width][step] === undefined) {
valueFromPxPositionLookupMap[width][step] = {};
}
if (valueFromPxPositionLookupMap[width][step][max] === undefined) {
valueFromPxPositionLookupMap[width][step][max] = {};
}
if (valueFromPxPositionLookupMap[width][step][max][min]=== undefined) {
valueFromPxPositionLookupMap[width][step][max][min] = {};
}
if (valueFromPxPositionLookupMap[width][step][max][min][pxPosition] === undefined) {
valueFromPxPositionLookupMap[width][step][max][min][pxPosition] = {};
}
valueFromPxPositionLookupMap[width][step][max][min][pxPosition] = value;
}
};
var getValueFromPxPositionHash = function(pxPosition) {
var min = 50,
max = 1000,
step = 1,
width = 300;
var hash = pxPosition + '-' + min + '-' + max + '-' + step + '-' + width;
return valueFromPxPositionLookupHash[hash];
};
var getValueFromPxPositionMap = function(pxPosition) {
var min = 50,
max = 1000,
step = 1,
width = 300;
return valueFromPxPositionLookupMap[width][step][max][min][pxPosition];
};
var getValueFromPxPosition = function(pxPosition) {
return valueFromPxPositionLookup[pxPosition];
};
var getValueFromPxPositionGo = function(pxPosition) {
var min = 50,
max = 1000,
step = 1,
width = 300;
var value = Math.round(
(min + (pxPosition / width) * (max - min)) / step
) * step;
if (value < min) {
value = min;
} else if (value > max) {
value = max;
}
return value;
};
populateValueFromPxPositionLookupHash();
populateValueFromPxPositionLookup();
populateValueFromPxPositionMap();
Ready to run.
Test | Ops/sec | |
---|---|---|
With hash |
| ready |
Without hash |
| ready |
On the go |
| ready |
map |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.