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
<script>
var rotateArray = function(a, inc) {
for (var l = a.length, inc = (Math.abs(inc) >= l && (inc %= l), inc < 0 && (inc += l), inc), i, x; inc; inc = (Math.ceil(l / inc) - 1) * inc - l + (l = inc))
for (i = l; i > inc; x = a[--i], a[i] = a[i - inc], a[i - inc] = x);
return a;
};
function reverse(a, from, to) {
--from;
while (++from < --to) {
var tmp = a[from];
a[from] = a[to];
a[to] = tmp;
}
}
function rotate(a, from, to, k) {
var n = to - from;
if (n > 0) {
k = (k % n + n) % n;
if (k > 0) {
reverse(a, from, from + k);
reverse(a, from + k, to);
reverse(a, from, to);
}
}
}
function circolarArray(array){
for(var i=0;i<array.length;i++){
var primo = array.shift();
array.push(primo);
}
}
var x = [];
var size = 1e3;
var i = -1;
while (++i < size) {
x.push(Math.floor(Math.random() * Math.pow(2, 30)));
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
rotate |
| ready |
rotateArray |
| ready |
circolarArray |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.