nextUntil tests (v2)

Revision 2 of this benchmark created by J R Schild on


Description

Exposes the following methods. They are all inserted into the external jQuery file.

  • nextMatchesSelectorUntil(): Behaves exactly the same as the current nextUntil(). Will throw an error if something else then a selector is used. Just like the current one.
  • nextFilterUntil(): Will use the filter() method instead of is(). Will accept both selectors, jQuery objects, DOM nodes and functions.
  • nextDOMOnlyUntil(): Only compares and accepts DOM nodes.
  • nextFullUntil(): First checks on DOM nodes, after that it will use filter(). Accepts everything.
  • nextIs2Until(): Uses the new is method ($.fn.is2()) from ticket 2773. Accepts everything

All methods end with Until to make sure a regex passes.
Also note that I think that it somehow feels wrong to create a new jQuery instance on each iteration just to check if those nodes are the same. Any help will be appreciated here.

while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) )

Preparation HTML

<script src="https://dump.jruitenschild.nl/jquery-1.4.4-fasternextUntil-5.js"></script>

<div id="testCase">
<dl>
<dt id="term-1">term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dd>definition 1-e</dd>

<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dd>definition 2-d</dd>
<dd>definition 2-e</dd>

<dt id="term-3">term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
<dd>definition 3-c</dd>
<dd>definition 3-d</dd>
<dd>definition 3-e</dd>
</dl>
</div>
<script>
  main = $('#testCase');
  term2 = main.find('#term-2');
  term3 = main.find('#term-3');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
standard nextUntil
// Selectors only
term2.nextUntil('#term-3');
ready
matchesSelector instead of is()
// Selectors only
term2.nextMatchesSelectorUntil('#term-3');
ready
Filter instead of .is()
// Accepts everything
term2.nextFilterUntil('#term-3');
ready
Filter instead of .is()
// Accepts everything
term2.nextFilterUntil(term3[0]);
ready
Filter instead of .is()
// Accepts everything
term2.nextFilterUntil(term3);
ready
DOM nodes only
// DOM nodes only
term2.nextDOMOnlyUntil(term3[0]);
ready
1. DOM-node 2. Filter
// Accepts everything
term2.nextFullUntil('#term-3');
ready
1. DOM-node 2. Filter
// Accepts everything
term2.nextFullUntil(term3[0]);
ready
1. DOM-node 2. Filter
// Accepts everything
term2.nextFullUntil(term3);
ready
New $.fn.is()
// Accepts everything
term2.nextIs2Until('#term-3');
ready
New $.fn.is()
// Accepts everything
term2.nextIs2Until(term3[0]);
ready
New $.fn.is()
// Accepts everything
term2.nextIs2Until(term3);
ready

Revisions

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

  • Revision 1: published by J R Schild on
  • Revision 2: published by J R Schild on