.size() vs .size() === (v2)

Revision 2 of this benchmark created on


Description

.size() vs .size() === 1

Preparation HTML

<div></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
  var $collection = $('div');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
check first
if ($collection.size() === 1) {
  $collection.each(function () { $(this).text('a'); });
}
ready
simple check for truth
if ($collection.size()) {
  $collection.each(function () { $(this).text('a'); });
}
ready
test with potential coercion
if ($collection.size() == 1) {
  $collection.each(function () { $(this).text('a'); });
}
ready
:?
$collection.size() === 1 ? $collection.each(function () { $(this).text('a'); }) : '';
ready
?: with ==
$collection.size() == 1 ? $collection.each(function () { $(this).text('a'); }) : '';
ready
:? with no check
$collection.size() ? $collection.each(function () { $(this).text('a'); }) : '';
ready

Revisions

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