Test Loop

Benchmark created by Tien on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var myArray = [1,2,3,4];

Test runner

Ready to run.

Testing in
TestOps/sec
each loop
// This look great
$.each(myArray, function(i, item) {
  var newListItem = "<li>" + item + "</li>";
  $("body").append(newListItem);
});
ready
each loop using fragment
// This BETTER (using fragment to improve performance
var frag = document.createDocumentFragment();
$.each(myArray, function(i, item) {
  var newListItem = document.createElement("li");
  var itemText = document.createTextNode(item);
  newListItem.appendChild(itemText);
  frag.appendChild(newListItem);
});
$("body")[0].appendChild(frag);
ready

Revisions

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