for values vs find

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<select id="Loremipsum" style="display: inline-block;">
  <option value='0'>
    Lorem
  </option>
  <option value='1'>
    ipsum
  </option>
  <option value='2'>
    dolor
  </option>
  <option value='3'>
    sit
  </option>
  <option value='4'>
    amet
  </option>
  <option value='5'>
    consectetur
  </option>
  <option value='6'>
    adipisicing
  </option>
  <option value='7'>
    elit
  </option>
  <option value='8'>
    sed
  </option>
  <option value='9'>
    do
  </option>
  <option value='10'>
    eiusmod
  </option>
  <option value='11'>
    tempor
  </option>
  <option value='12'>
    incididunt
  </option>
  <option value='13'>
    ut
  </option>
  <option value='14'>
    labore
  </option>
  <option value='15'>
    et
  </option>
  <option value='16'>
    dolore
  </option>
  <option value='17'>
    magna
  </option>
  <option value='18'>
    aliqua.
  </option>
  <option value='19'>
    Ut
  </option>
  <option value='20'>
    enim
  </option>
  <option value='21'>
    ad
  </option>
  <option value='22'>
    minim
  </option>
  <option value='23'>
    veniam
  </option>
  <option value='24'>
    quis
  </option>
  <option value='25'>
    nostrud
  </option>
  <option value='26'>
    exercitation
  </option>
  <option value='27'>
    ullamco
  </option>
  <option value='28'>
    laboris
  </option>
  <option value='29'>
    nisi
  </option>
  <option value='30'>
    ut
  </option>
  <option value='31'>
    aliquip
  </option>
  <option value='32'>
    ex
  </option>
  <option value='33'>
    ea
  </option>
  <option value='34'>
    commodo
  </option>
  <option value='35'>
    consequat.
  </option>
  <option value='36'>
    Duis
  </option>
  <option value='37'>
    aute
  </option>
  <option value='38'>
    irure
  </option>
  <option value='39'>
    dolor
  </option>
  <option value='40'>
    in
  </option>
  <option value='41'>
    reprehenderit
  </option>
  <option value='42'>
    in
  </option>
  <option value='43'>
    voluptate
  </option>
  <option value='44'>
    velit
  </option>
  <option value='45'>
    esse
  </option>
  <option value='46'>
    cillum
  </option>
  <option value='47'>
    dolore
  </option>
  <option value='48'>
    eu
  </option>
  <option value='49'>
    fugiat
  </option>
  <option value='50'>
    nulla
  </option>
  <option value='51'>
    pariatur.
  </option>
  <option value='52'>
    Excepteur
  </option>
  <option value='53'>
    sint
  </option>
  <option value='54'>
    occaecat
  </option>
  <option value='55'>
    cupidatat
  </option>
  <option value='56'>
    non
  </option>
  <option value='57'>
    proident
  </option>
  <option value='58'>
    sunt
  </option>
  <option value='59'>
    in
  </option>
  <option value='60'>
    culpa
  </option>
  <option value='61'>
    qui
  </option>
  <option value='62'>
    officia
  </option>
  <option value='63'>
    deserunt
  </option>
  <option value='64'>
    mollit
  </option>
  <option value='65'>
    anim
  </option>
  <option value='66'>
    id
  </option>
  <option value='67'>
    est
  </option>
  <option value='68'>
    laborum
  </option>
</select>
<script>
Benchmark.prototype.setup = function() {
    var ExcludeCategories = [5, 25, 49];
    var contRef = $('Loremipsum');
};
</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
Each Find
function removeChildren(container, values) {
  var container = jQuery(container);

  values.each(function(val) {
    //Could check .length to see if existed
    container.find("option[value='" + val + "']");
  });
}(contRef, ExcludeCategories);
pending…
For InArray
function removeChildren(container, values) {
  var container = jQuery(container);

  for (var i = 0; i < container.options.length; ++i) {
    if (jQuery.inArray(container.options[i].val(), values)) {
      container.options[i];
    }
    }
  }(contRef, ExcludeCategories);
pending…

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

Compare results of other browsers

0 comments

Add a comment