Slow loop (v4)

Revision 4 of this benchmark created on


Description

Comparing the "slow loop" argument from http://www.sitepoint.com/google-closure-how-not-to-write-javascript/

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  < script type = "text/javascript" >
  
  var AccordionLink = "<asp:Literal id='sAccordionLink' runat='server' />";
  var status = "<asp:Literal id='sStatuLink' runat='server' />";
  
  function ResolveUrl(url) {
    if (url.indexOf("~/") == 0) {
      url = baseUrl + url.substring(2);
    }
    return url;
  }
  Ektron.ready(function() {
    if ("True" == status) {
  
      $.ajax({
        type: "POST",
        cache: false,
        async: false,
        url: AccordionLink,
        success: function(data) {
          var st = $(data).filter('#EOR').html();
          $("#devsite-method-description").html(st);
        }
      });
      $('#devsite-method-description img').each(function() {
        var imgSrc = $(this).attr('src');
        imgSrc = imgSrc.replace("../../../", "developer/doc/Content/");
        var baseUrl = "<%= ResolveUrl("~ / ") %>";
        imgSrc = baseUrl + imgSrc;
        $(this).attr('src', imgSrc);
      });
    }
  
  
  }); < /script>
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
"Slow" loop
for (var i = 0; i < arr.length; i++) {
  highest = i;
}
ready
"Fast" loop
for (var i = 0, len = arr.length; i < len; i++) {
  highest = i;
}
ready
"Fastest" loop
var i = arr.length;
while (i--) {
  lowest = i;
}
ready

Revisions

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