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
This new version adds a new function which defers the modulo operation till the end. This avoids excessive modulo operations and avoids some bookkeeping, further contributing to the speed of the implementation.
<script>
//--------------------------------------------------
// simple impl
//--------------------------------------------------
function adler32_simple(array) {
return adler32_simple_update(1, array);
}
function adler32_simple_update(adler, array) {
var s1 = adler & 0xffff,
s2 = (adler >>> 16) & 0xffff;
for (var i = 0, l = array.length; i < l; i++) {
s1 = (s1 + array[i]) % 65521;
s2 = (s2 + s1) % 65521;
}
return ((s2 << 16) | s1) >>> 0;
}
//--------------------------------------------------
// optimized impl
//--------------------------------------------------
function adler32_opti(array, param) {
return adler32_opti_update(1, array, param);
}
function adler32_opti_update(adler, array, param) {
var s1 = adler & 0xffff,
s2 = (adler >>> 16) & 0xffff;
var len = array.length;
var tlen;
var i = 0;
while (len > 0) {
tlen = len > param ? param : len;
len -= tlen;
do {
s1 += array[i++];
s2 += s1;
} while (--tlen);
s1 %= 65521;
s2 %= 65521;
}
return ((s2 << 16) | s1) >>> 0;
}
function adler32_fulllength(array) {
var a = 1;
var b = 0;
var len = array.length;
for (var i = 0; i < len; i++) {
a += array[i];
b += a;
}
a %= 65521;
b %= 65521;
return (b << 16) | a;
}
</script>
var testData = [];
var num = 100000;
for (var i = 0; i < num; ++i) {
testData[i] = (i * 2) & 0xff;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
simple |
| ready |
opti(16) |
| ready |
opti(32) |
| ready |
opti(64) |
| ready |
opti(128) |
| ready |
opti(256) |
| ready |
opti(512) |
| ready |
opti(1024) |
| ready |
opti(2048) |
| ready |
opti(4096) |
| ready |
opti(5550) |
| ready |
full-length |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.