Test JS Length in Loop

JavaScript performance comparison

Test case created by Karmi Phúc

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = new Array(10000),
      len, i;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Length in Loop
for (i = 0; i < arr.length; i++) {
  // Không tốt - phải tìm giá trị arr.length 10000 lần
  console.log('Test');
}
pending…
Length is stored
for (i = 0, len = arr.length; i < len; i++) {
  // Tốt - giá trị arr.length chỉ cần tìm 1 lần
  console.log('Test');
}
pending…

Compare results of other browsers

Revisions

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

0 Comments