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
Testing out two (seemingly different) shuffling algorithms.
<script>
var modernExample = function() {
var arr = generateRandomArray(),
j, tmp;
for (var i = arr.length - 1; i > 0; i--) {
// get a random number between 0 & i
j = randomNum(0, i);
// do the switchero
tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
return arr;
},
msShuffleExample = function() {
var arr = generateRandomArray(),
tmp, len = arr.length;
while (len) {
c = Math.floor(Math.random() * len);
tmp = arr[--len];
arr[len] = arr[c];
arr[c] = tmp;
}
return arr;
},
generateRandomArray = function() {
var arr = [],
num;
for (var i = 0; i < 25; i++) {
num = parseInt(Math.random() * (999 - 1) + 1, 10);
if (num) {
arr.push(num);
}
}
return arr;
},
//function to get random number upto m
randomNum = function(minVal, maxVal) {
var randVal = minVal + (Math.random() * (maxVal - minVal));
return Math.round(randVal);
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Modern Example |
| ready |
MS Shuffle Example |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.