find() & remove() vs empty()

JavaScript performance comparison

Test case created by vzwick

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<select id="mySelect">
  <option value="volvo">
    Volvo
  </option>
  <option value="saab">
    Saab
  </option>
  <option value="mercedes">
    Mercedes
  </option>
  <option value="audi">
    Audi
  </option>
</select>
    

Preparation code output

<select id="mySelect"> <option value="volvo"> Volvo </option> <option value="saab"> Saab </option> <option value="mercedes"> Mercedes </option> <option value="audi"> Audi </option> </select>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
find() & remove()
$('#mySelect').find('option').remove().end().append('<option value="whatever">text</option>').val('whatever');
pending…
empty()
$('#mySelect').empty().append('<option selected="selected" value="whatever">text</option>');
pending…
options.length = 0
$select = $('#mySelect');
$select[0].options.length = 0;
$select.append('<option selected="selected" value="whatever">text</option>');
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.

0 Comments