Loops: Caching Length of Array That Is Out of Function Scope

JavaScript performance comparison

Revision 4 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  (self || global).oTest = {
      aX: "Soufflé donut ice cream. Dragée danish jelly beans cotton candy oat cake. Candy canes caramels tiramisu bear claw muffin icing. Marshmallow jujubes faworki dessert. Bear claw chocolate cake chocolate cake brownie sesame snaps brownie faworki. Jelly-o gummi bears fruitcake cotton candy marshmallow jujubes cookie. Pie toffee tart tootsie roll bonbon cake. Halvah sweet pastry cookie croissant chupa chups candy canes. Chocolate jelly chocolate bar caramels applicake cotton candy caramels donut. Toffee jelly-o brownie pie bonbon gummies marshmallow topping. Toffee chupa chups sesame snaps caramels tootsie roll bear claw faworki macaroon chocolate. Jelly beans chupa chups caramels pudding wypas oat cake chocolate cake.".split(" ")
  };

};

Benchmark.prototype.teardown = function() {
  (self || global).oTest = undefined;

};
</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
Cached Length
(function yet_another_loop_length_cache_test_1() {

  var aX = (self || global).oTest.aX,
      i  = 0,
      iL = aX.length;

  for(; i < iL; i++) {
      aX[ i ] += ".";
  }

})();
pending…
No Cached Length
(function yet_another_loop_length_cache_test_2() {

  var aX = (self || global).oTest.aX,
      i  = 0;

  for(; i < aX.length; i++) {
      aX[ i ] += ".";
  }

})();
pending…
No Cached Reference
(function yet_another_loop_length_cache_test_3() {

  var i = 0;

  for(; i < oTest.aX.length; i++) {
      oTest.aX[ i ] += ".";
  }

})();
pending…
Cached Length from Non-specific Global
(function yet_another_loop_length_cache_test_4() {

  var aX = oTest.aX,
      i  = 0,
      iL = aX.length;

  for(; i < iL; i++) {
      aX[ i ] += ".";
  }

})();
pending…
Cached Length from Specific 'self' Global
(function yet_another_loop_length_cache_test_5() {

  var aX = self.oTest.aX,
      i  = 0,
      iL = aX.length;

  for(; i < iL; i++) {
      aX[ i ] += ".";
  }

})();
pending…
Cached Length from Specific 'window' Global
(function yet_another_loop_length_cache_test_6() {

  var aX = window.oTest.aX,
      i  = 0,
      iL = aX.length;

  for(; i < iL; i++) {
      aX[ i ] += ".";
  }

})();
pending…
No cached length, non-specific global
(function yet_another_loop_length_cache_test_7() {

  var aX = oTest.aX,
      i  = 0;

  for(; i < aX.length; i++) {
      aX[ i ] += ".";
  }

})();
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