Emptying a select box (v7)

Revision 7 of this benchmark created on


Preparation HTML

<select id="box" style="display:none;">
</select>

Setup

var box = document.getElementById("box");
    var s = [];
    for (var i = 1; i <= 5000; ++i) {
      s += "<option>Option " + i + "</option>\n";
    }
    box.innerHTML = s;

Test runner

Ready to run.

Testing in
TestOps/sec
box.innerHTML = ""
box.innerHTML = "";
ready
box.options.length = 0
box.options.length = 0;
ready
box.removeChild (first)
while (box.options.length) {
  box.removeChild(box.options[0]);
}
ready
box.removeChild (last)
var len;
while (len = box.options.length) {
  box.removeChild(box.options[len - 1]);
}
ready
optimized
if (!window.chrome) {
  var len;
  while (len = box.options.length) {
    box.removeChild(box.options[len - 1]);
  }
} else {
  box.options.length = 0;
}
ready

Revisions

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