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
A potential use case for dynamically unrolling loops at runtime. If you know ahead of time how many iterations you will have this can speed up execution considerably.
var outerLoops = 100;
var innerLoops = 16;
var c = ["var plus = function(a, b) {return a + b;};var sum = 0;for (var i = 0; i < " + outerLoops + "; i++) {"];
for (var i = 1; i <= innerLoops; i++) {
c[i] = "sum=plus(sum,i);"
}
c.push("};return sum;")
var once = Function(c.join(""));
var c = ["var plus = function(a, b) {return a + b;};var sum = 0;for (var i = 0; i < " + outerLoops + "; i++) {"];
for (var i = 1; i <= innerLoops; i++) {
c[i] = "sum=sum+i;"
}
c.push("};return sum;")
var once2 = Function(c.join(""));
var plus = function(a, b) {
return a + b;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Loop In Loop |
| ready |
Dynamically Unrolled Loop (Function recreated every test) |
| ready |
Dynamically Unrolled Loop (Function created once) |
| ready |
Dynamically Unrolled Loop (Function body extracted) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.