find() & remove() vs empty()

JavaScript performance comparison

Test case created by vzwick

Preparation code

<script src="//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

Test runner

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

Java applet disabled.

Testing in unknown unknown
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. Here’s a list of current revisions for this page:

0 comments

Add a comment