Using length magic function is bad
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = [1,2,3,4,5,6,7,8,9,0,123,12,1,41,24,124,124,124,1245,13,52,35,233,5,2345,34,63,46,36,34,63,46,346,3,763,7,3457,35,234,35,57,35,3346,36,3,63,4,4,6,8,4,8456,84,5,3,612,36,347,3,734,57,457,45,735,74,57,47,3,46];
var len = a.length;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
using length in the for loop |
|
pending… |
caching length before the loop |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments