Emptying a select box

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<select id="box">
</select>
<script>
  var box = document.getElementById("box");
  var n = 2000;
</script>
<script>
Benchmark.prototype.setup = function() {
    var s = [];
    for (var i = 1; i <= 1000; ++i) {
      s += "<option>Option " + i + "</option>\n";
    }
    box.innerHTML = s;
};
</script>

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
box.innerHTML = ""
box.innerHTML = "";
pending…
box.options.length = 0
box.options.length = 0;
pending…
box.removeChild
while (box.options.length) {
  box.removeChild(box.options[0]);
}
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