Function assignment

JavaScript performance comparison

Test case created by Matt

Preparation code

<ul id="list">
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
<script>
  var ul = document.getElementById('list');
  var lis = ul.children;
</script>

Preparation code output

  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item
  • List item

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Option 1
for(var li in lis){
     lis[li].onclick = function(){ this.style.backgroundColor = "red" };
}
pending…
Option 2
function turnRed(){
     this.style.backgroundColor = "red";
}

for(var li in lis){
     lis[li].onclick = turnRed;
}
pending…

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

Compare results of other browsers

0 comments

Add a comment