t

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<select name="test" id="test">
        <option value="test1">a</option>
        <option value="test2">b</option>
        <option value="test3">c</option>
        <option value="test4">d</option>
        <option value="test5" selected>e</option>
        <option value="test6">f</option>
        <option value="test7">g</option>
        <option value="test8">h</option>
        <option value="test9">i</option>
        <option value="test10">j</option>
        <option value="test11">k</option>
        <option value="test12">l</option>
        <option value="test13">m</option>
</select>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
t1
node = document.querySelector('select');
selectedOption = node.querySelector('option:checked');
pending…
t2
node = document.querySelector('select');
[].forEach.call(node.options, function(option) {

  if (option.selected) {
    selectedOption = option;
  }
});
pending…
t3
node = document.querySelector('select');
for (var i = 0, len = node.options.length; i < len; i += 1) {
  if (node.options[i].selected) {
    selectedOption = node.options[i];
  }
};
pending…
t4
node = document.querySelector('select');
for (var i = 0, len = node.options.length; i < len; i += 1) {
  if (node.options[i].selected) {
    selectedOption = node.options[i];
    break;
  }
};
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. Here’s a list of current revisions for this page:

0 comments

Add a comment