.length vs cache

Benchmark created by loop .length vs caching length on


Preparation HTML

<script>
 var a = [];
 
 for (var i = 0; i < 100; i++) {
  a[i] = i;
 }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
cache
var len = a.length;
for (var j = 0; j < len; j++) {}
ready
length
for (var j = 0; j < a.length; j++) {}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by loop .length vs caching length on