jq.eq(index) vs jq( jqobj[index] ) (v3)

Revision 3 of this benchmark created by everywhile on


Preparation HTML

<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
<p>10</p>
<p>11</p>
<p>12</p>
<p>13</p>
<p>14</p>
<p>15</p>
<p>16</p>
<p>17</p>
<p>18</p>
<p>19</p>
<p>20</p>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
var jq161 = jQuery.noConflict(true);
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
var jq182 = jQuery.noConflict(true);
jq182.fn.newEq = function( i ) {
    var len = this.length,
        j = i < 0 ? +i + len : +i;
    return this.pushStack( j >= 0 && j < len && [ this[j] ] );
};
jq182.fn.simpleEq = function( i ) {
    if (i < 0) i+= len;
    return this.pushStack([this[i]]);
};
</script>

Setup

var grafs161 = jq161("p"),
    grafs182 = jq182("p"),
    grafsNew = jq182("p"),
    grafsSimple = jq182("p");

Test runner

Ready to run.

Testing in
TestOps/sec
1.6.1 .eq()
grafs161.eq(5);
ready
1.6.1 rewrap
jq161( grafs161[5] );
ready
1.8.2 .eq()
grafs182.eq(5);
ready
1.8.2 rewrap
jq182( grafs182[5] );
ready
New .eq()
grafsNew.newEq(5);
ready
simple
grafs182.simpleEq(5);
ready

Revisions

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