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 test compares the performance of global variables to local variables within functions.
Global variables should be slower because they do not exist in a function's activation object. JavaScript must traverse the Scope Chain to locate global variables.
<script>
var a = 0;
var c = [];
function x() {
a = 0;
}
function w() {
var b = 0;
}
function arrayGlobal () {
c = [];
for (var i = 0; i < 10; i++) {
c[i] = i;
}
}
function arrayLocal () {
var d = [];
for (var i = 0; i < 10; i++) {
d[i] = i;
}
}
function arrayGlobal2 () {
c = [];
c[0] = 0;
}
function arrayLocal2 () {
var d = [];
d[0] = 0;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Global variables |
| ready |
Local variables |
| ready |
Global Array |
| ready |
Local Array |
| ready |
Global Array 2 |
| ready |
Local Array 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.