Array.length vs Counter vs Length = Array.push

Benchmark created by rolandog on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
 var a, l = 0,
     i;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Array.length
a = [];
i = 100;
do {
 a.push(i);
 i -= 1;
} while (i);
l = a.length;
ready
Counter
a = [];
i = 100;
do {
 a.push(i);
 i -= 1;
 l += 1;
} while (i);
ready
l = Array.push
a = [];
i = 100;
do {
 l = a.push(i);
 i -= 1;
} while (i);
ready

Revisions

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

  • Revision 1: published by rolandog on