map vs. each (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<ul>
    <li class="funny">Funny company 1</li>
    <li class="boring">Boring company 1</li>
    <li class="funny">Funny company 2</li>
    <li class="boring">Boring company 2</li>
</ul>

<select multiple="multiple" size="5">
    <option value="funny">Funny companies</option>
    <option value="boring">Boring companies</option>
</select>

Test runner

Ready to run.

Testing in
TestOps/sec
.map
$(function() {
 $('select').change(function() {
  var $this = $(this);
  $('li').hide();
  var a = $.map($this.children(':selected'), function(b) {
   return $(b).attr('value');
  });
  $("li." + a.join(".")).show()
 });
 $('option:first').click();
 $('option:last').click();
});
ready
.each
$(function() {
 $('select').change(function() {
  var $this = $(this);
  $('li').hide();
  $this.children(':selected').each(function() {
   $('li.' + $(this).attr('value')).show();
  });
 });
 $('option:first').click();
 $('option:last').click();
});
ready

Revisions

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