jQuery("#id")

JavaScript performance comparison

Revision 6 of this test case created by Timmy Willison

Info

The duplicate id optimization in jQuery.fn.init has been removed. Check the loss.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
var $1_7_2 = jQuery.noConflict();
</script>
<script src="//code.jquery.com/jquery-git.js"></script>
<script>
var $git = jQuery.noConflict();
</script>
<div id="test" class="test">
<div id="child"></div>
</div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div class="test"></div>
<div style="display:none;"><div id="page"><div id="masthead"><div id="mastheadhd"></div><div id="mastheadbd"><div class="mastheadbd"><div id="eyebrow"><ul id="ypromo"><li><a id="sethomepage" href=""><strong>Make Y! your home page</strong></a></li><li id="toolbar"><a id="dtba" href=""><span id="tba">Get</span> Yahoo! Toolbar</a></li></ul><div id="ffhpcx"></div><div id="headline"><span><a href="">How much home can you afford?</a></span></div></div><h1><img src="blank.gif" border=0 width=232 height=44 alt="Yahoo!" id="ylogo"></h1><div id="searchwrapper"><form name="sf1" id="search" action="r/sx/*-http://search.yahoo.com/search"><fieldset><legend>Yahoo! Search</legend><ul id="vsearchtabs"><li class="first on"><a href="">Web</a></li><li><a href="">Images</a></li><li><a href="">Video</a></li><li><a href="">Local</a></li><li><a href="">Shopping</a></li><li class="last ignore"><dl id="vsearchm"><dt><a id="vsearchmore" href="">More</a></dt><dd id="vslist"></dd></dl></li></ul><div id="sbox"><label id="searchlabel" for="p">Search:</label><div class="outer_search_container"><div id="search_container" class="search_container"><img src="blank.gif" id="searchother_e2e" alt=""><div id="searchIE"><div id="searchmw1" class="iemw"></div></div><div class="fixfloat searchbox_container"><div id="searchbox"><input class="plong inputtext" type="text" id="p" name="p" accesskey="s"></div><span id="searchbtn"><input type="submit" id="searchsubmit" class="btn-more-2" value="Web Search"></span></div></div><div id="e2eClass" class="e2e"><div class="e2eTween"></div><div id="e2e"><div id="e2econtent"><div id="e2e_intl"></div><div class="ac_container"><div id="e2einfo"></div><div id="ac_container"></div><div id="e2escroll"></div></div></div><a title="toggle search suggestions" id="e2etoggle" href="" onclick="return false;"><img src="blank.gif" id="searchtoggle_e2e" alt="toggle search suggestions"></a></div></div></div><input type="hidden" name="fr" value="yfp"><input type="hidden" name="toggle" value="1"><input type="hidden" name="cop" value="mss"><input type="hidden" name="ei" value="UTF-8"></div><div id="sboxfooter"></div></fieldset></form></div><div class="mh_footer"><div id="doors"><h3 class="a11y">Popular Yahoo! Properties</h3><ul id="doors-links" class="fixfloat"><li class="first"><strong>Yahoo! Home</strong></li><li class="middle"><a href=r/i1 title="Go to My Yahoo!">My Yahoo!</a></li><li class="last"></li></ul></div><div id="pagesettingscx"><span id="navbardate"><cite class="timestamp">&nbsp;</cite></span><a href="" id="editpage">Page Options</a><div id="pagesettings"><div class="bd"><span><div class="iemw"></div><div id="pscolors"><h4>Color:</h4><ol id="themes"><li><a href="" id="t1" class="on" title="Ocean">Ocean</a></li><li><a href="" id="t4"  title="Tangerine">Tangerine</a></li><li><a href="" id="t3"  title="Violet">Violet</a></li><li><a href="" id="t2"  title="Oyster">Oyster</a></li><li><a href="" id="t5"  title="Grass">Grass</a></li><li><a href="" id="t7"  title="Pink">Pink</a></li></ol></div><a id="sizetogglelink" href="">Switch to narrow layout</a><a id="myyahoolink" href="">Want more ways to customize <span>your home page?</span><span class="trymyyahoo">Try My Yahoo! &#187;</span></a></span></div></div></div></div></div></div><div id="mastheadft"></div></div><div id="colcx"><div id="left"><div id="trough" class="md"><div class="bd"><div id="trough-cols" class="fixfloat"><ul id="trough-1" class="col1"><li><a style="background-position:-400px -120px" href="">Answers</a></li><li><a style="background-position:-400px -440px" href="">Autos</a></li><li><a style="background-position:0 -761px" href="">Finance</a></li><li><a style="background-position:0 -1600px" href="">Games</a></li><li><a style="background-position:0 -1400px" href="">Groups</a></li><li><a style="background-position:0 -439px" href="">HotJobs</a></li><li><a style="background-position:0 -600px" href="">Maps</a></li><li><a style="background-position:0 -161px" href="">Mobile Web</a></li><li><a style="background-position:0 -561px;display:inline" href="">Movies</a> | <a class="trough_tv" href="">TV</a></li><li><a style="background-position:0 -1562px" href="">Music</a></li><li><a style="background-position:-400px -1119px" href="">OMG</a></li><li class="highlight"><a style="background-position:0 -40px" href="">Personals</a></li><li><a style="background-position:-400px -161px" href="">Real Estate<small class="updated"></small></a></li><li><a style="background-position:-400px -1321px" href="">Shine</a></li><li><a style="background-position:0 -1640px" href="">Shopping</a></li><li><a style="background-position:0 -800px" href="">Sports</a></li><li><a style="background-position:0 -79px" href="">Travel</a></li><li><a style="background-position:0 -121px" href="">Yellow Pages</a></li></ul></div><span id="allyservicescx"><a href="" id="allyservices" class="btn-more-2" title="View the complete list of Yahoo! Services">More Yahoo! Services</a></span></div></div><div class="md minimantle"><div id="smallbiz" class="md-sub"><div class="hd"><h2><a href="">Small Business</a></h2></div><ul id="smallbiz-links"><li><a href="">Get a Web Site</a></li><li><a href="">Domain Names</a></li><li><a href="">Sell Online</a></li><li><a href="">Search Ads</a></li></ul></div></div><div class="md minimantle"><div id="advertising" class="md-sub"><div class="hd"><h2><a href="">Featured Services</a></h2></div><ul id="advertising-links"><li><a href="">Downloads</a></li><li><a href="">Health</a></li><li><a href="">Kids</a></li><li><a href="">GeoCities</a></li><li><a href="">Mail Plus</a></li><li><a href="">Y! International</a></li></ul></div></div></div><div id="rightcx"><div id="middle"><div class="colpadding"><div id="today" class="md featured1"><div class="hd tabs"><h3 class="a11y">Featured Navigation</h3><ul id="todaytabs"><li class="on first"><em><a hidefocus="true" id="featured1" href="">Featured</a></em><span class="pipe"></span></li><li class="tab2"><em><a hidefocus="true" id="entertainment1" href="">Entertainment</a></em><span class="pipe"></span></li><li class="tab3"><em><a hidefocus="true" id="sports1" href="">Sports</a></em><span class="pipe"></span></li><li class="last"><em><a hidefocus="true" id="money1" href="">Video</a></em><span class="pipe"></span></li></ul></div><div id="todayvideo"></div><div id="todaybd" class="bd"><cite class="timestamp">&nbsp;</cite><span id="featured1ct" class="current"><div id="featured1main"><a href=s/1014544><img src="blank.gif" width="154" height="115" alt="Renee Zellweger (Steve Grantiz/WireImage)"></a><span><h3><a href=s/1014544>Worst dressed at the Globes</a></h3><p>Renee's look is a mess, and Miley's gown is a mistake. <a class=more href=s/1014544>&#187; See bad outfits</a></p><ul><li><a class=slideshow href=s/1014545>Best dressed</a></li><li><a class=slideshow href=s/1014546>Stunning couples</a></li><li><a class=video href=s/1014547>Watch Brangelina diss Ryan Seacrest</a></li><li><a class=bullet href=s/1014548>Outrageous moments</a></li><li><a class=bullet href=s/1014549>Big winners</a></li></ul></span></div></span><span id="featured2ct"></span><span id="featured3ct"></span><span id="featured4ct"></span><span id="entertainment1ct"></span><span id="entertainment2ct"></span><span id="entertainment3ct"></span><span id="entertainment4ct"></span><span id="sports1ct"></span><span id="sports2ct"></span><span id="sports3ct"></span><span id="sports4ct"></span><span id="money1ct"></span><span id="money2ct"></span><span id="money3ct"></span><span id="money4ct"></span></div><div id="todayft" class="ft"><span id="footer1" class="current"><ul id="todaystories1"><li id="featured1|106537" class="on"><a href=s/1014556><img src="blank.gif" alt="" width="29" height="21">See the worst-dressed stars at Golden Globes</a></li><li id="featured2|106533"><a href=s/1014475><img src="blank.gif" alt="" width="29" height="21">Obama: Dog search down to two breeds</a></li><li id="featured3|106522"><a href=s/1014275><img src="blank.gif" alt="" width="29" height="21">Eagles star gets penalty for 'phone call'</a></li><li id="featured4|106538"><a href=s/1014566><img src="blank.gif" alt="" width="29" height="21">Teen sends 14,528 texts in one month</a></li></ul><div id="more-featured" class="btn-more"><b>&#187;</b> More:<a class="first" href="">Featured</a><a class="last" href="">Buzz</a></div></span><span id="footer2"></span><span id="footer3"></span><span id="footer4"></span></div></div><div id="adwest" class="ad"></div><div id="news" class="md"><div class="hd tabs"><h3 class="a11y">News Navigation</h3><ul id="newstabs"><li class="on first"><em><a hidefocus="true" id="inthenews2" href="">News</a></em><span class="pipe"></span></li><li class="tab2"><em><a hidefocus="true" id="worldnews" href="">World</a></em><span class="pipe"></span></li><li class="tab3"><em><a hidefocus="true" id="localnews" href="">Local</a></em><span class="pipe"></span></li><li class="last"><em><a hidefocus="true" id="finsnews" href="">Finance</a></em><span class="pipe"></span></li></ul></div><div id="newsbd" class="bd"><span id="inthenews2ct" class="current"><h2 class="a11y">In the News</h2><div id="newstop"><cite class="timestamp">&nbsp;</cite>&#149;&nbsp;<a href=s/1014558>Obama advises Bush to request remaining $350B of bailout</a><br>&#149;&nbsp;<a href=s/1014502>Bush defends his presidency in final news conference</a><br>&#149;&nbsp;<a href=s/1014534>More than 900 Gazans dead as Israel continues attacks</a><br>&#149;&nbsp;<a href=s/1014517>Openly gay Episcopal bishop to say prayer at inaugural event</a><br>&#149;&nbsp;<a href=s/1014567>NYC judge allows Bernard Madoff to remain free on bail</a><br>&#149;&nbsp;<a href=s/1014516>British PM backing Prince Harry after racist remark</a><br>&#149;&nbsp;<a class=video style="background-position:-3px -48px;font:normal 100% arial;" href=s/1014537 onclick="window.open('s/1014537','playerWindow','width=793,height=608,scrollbars=no');return false;">Brothers separated at birth reunite after 80 years</a><br><ul id="more-news" class="btn-more"><li class="first"><b>&#187;</b> More:</li><li><a href=r/xn>News</a></li><li><a href=r/me>Popular</a></li><li class="last"><a href=r/z0>Politics</a></li></ul></div><div id="newsft"><div id="newsbottom"><div id="finance-data"><div id="markets"><h3><a href="">Markets:</a></h3><ul><li><strong><a href="">Dow: </a><span class="down">-1.0%</span></strong></li><li><strong><a href="">Nasdaq: </a><span class="down">-1.7%</span></strong></li></ul></div><div id="quotes"><form name="fq" id="fq" action="r/f4/*-http://finance.yahoo.com/q"><fieldset><legend>Yahoo! Finance</legend>     <a href="">Real-Time Quotes:</a><input accesskey="q" class="inputtext" type="text" id="s" name="s" size="5" title="Enter ticker symbol" /><input type="submit" class="submit" value="Go" /></fieldset></form></div></div><div id="news-sponsor"><a href=""><img src="blank.gif" border=0 width=165 height=15 title="Switch to Scottrade"></a></div></div></div></span><span id="worldnewsct"></span><span id="localnewsct"></span><span id="finsnewsct"></span></div></div><div id="marketplace" class="md"><div class="hd"><h2><a href="" name="marketplace">Marketplace</a></h2></div><div id="marketplacebd" class="bd"><table border=0 cellpadding=0 cellspacing=0 width="100%"><tr><td valign=top><a href=""><img src="blank.gif" width=70 height=50 border=0></a></td><td width=8>&nbsp;</td><td valign=top><font face=arial size=-1><a href="">Why online college is rocking:</a><br>1) Accredited Associates, Bachelor&#39;s, Master&#39;s, MBA degrees 2) Some jobs pay tuition <a href="">3) Top schools online.</a></font></td></tr></table><hr size=1 noshade><a href="">A bad credit score is 600 or below. Click here to see yours online in just 2 easy steps for $0. By Experian&reg;</a><hr size=1 noshade><a href="">GEICO Car Insurance -</a> You could save over $500 on car insurance. <a href="">Get a fast, free quote.</a><hr size=1 noshade><a href="">100+ credit cards from 9 of the top 10 issuers. Instant approvals. Choose the right card for you. LendingTree&reg;</a></div></div></div></div><div id="right"><div class="colpadding"><div id="pa" class="md"><div id="pabd"><div id="patop"><ul id="reg" class="so"><li class="mailstatus">Check your mail status: <a href="">Sign In</a></li><li id="signup">Free mail: <a href="">Sign Up</a></li></ul></div><div id="patabs"><ul id="tabs1" class="patabs first"><li id="mail" class="first"><div><h4><a id="pamail" accesskey="m" href=""><span class="icon">Mail</span></a></h4></div></li><li id="messenger"><div><h4><a id="pamsgr" href=""><span class="icon">Messenger</span></a></h4></div></li><li id="games" class="last"><div><h4><a id="pagames" href=""><span class="icon">Puzzles</span></a></h4></div></li></ul><div id="tabs1previewdiv" class="papreviewdiv"></div><ul id="tabs2" class="patabs last"><li id="weather" class="first"><div><h4><a id="paweather" href=""><span class="icon">Weather</span></a></h4></div></li><li id="events"><div><h4><a id="paevents" href=""><span class="icon">Events</span></a></h4></div></li><li id="horoscope" class="last"><div><h4><a id="pahoroscope" href=""><span class="icon">Horoscopes</span></a></h4></div></li></ul><div id="tabs2previewdiv" class="papreviewdiv"></div></div></div></div><div id="ad" class="ad"><table cellspacing=0 cellpadding=0 border=0 width=100%><tr><td align=center><a href="" target="_top"><img src="blank.gif" alt="" width=300 height=250 border=0></a></td></tr><tr><td align=center><br><font face="verdana" size="-2"><a href="" target="_blank">Ad Feedback</a></font></td></tr></table></div><div id="mantlecx"><div id="mantle"><div id="mantle2" class="md"><div class="hd"><h2><a href="">Inside Yahoo! HotJobs</a></h2>   </div><div class="bd"><a href=""><img src="blank.gif" height="68" width="92" alt="Yahoo! HotJobs" border="0"></a><h3><a href="">Great companies hiring now</a></h3><ul><li><a href="">Careers with bright futures</a></li><li><a href="">Low-stress jobs that pay</a></li><li><a href="">Super-easy career changes</a></li><li><a href="">How to find a job right for you</a></li></ul></div></div></div></div><div id="pulse" class="md"><div class="hd"><h2>Pulse - What Yahoos Are Into</h2></div><div id="pulsebd" class="bd"><h3>Star Searches: Most Popular Actors</h3><a href=s/1013525/*-http://movies.yahoo.com/movie/contributor/1800043966><img src="blank.gif" alt="Alyssa Milano (Steve Granitz, WireImage.com)" width="139" height="119"></a><ol><li class="tt1"><a href=s/1013525/*-http://movies.yahoo.com/movie/contributor/1800043966>Alyssa Milano</a></li><li class="tt2"><a href=s/1013526/*-http://movies.yahoo.com/movie/contributor/1800018965>Brad Pitt</a></li><li class="tt3"><a href=s/1013527/*-http://movies.yahoo.com/movie/contributor/1804705919>Anne Hathaway</a></li><li class="tt4"><a href=s/1013528/*-http://movies.yahoo.com/movie/contributor/1800424122>Ziyi Zhang</a></li><li class="tt5"><a href=s/1013529/*-http://movies.yahoo.com/movie/contributor/1800019484>Charlize Theron</a></li><li class="tt6"><a href=s/1013530/*-http://movies.yahoo.com/movie/contributor/1800019485>Johnny Depp</a></li></ol></div><a class=btn-more href=s/1013531/*-http://movies.yahoo.com>&#187; More Yahoo! Movies</a></div><div id="popsearch" class="md"><div class="hd"><h2>Today&#039;s Top Searches</h2></div><div id="popsearchbd" class="bd"><ol start=1><li><a href="">Odette Yustman</a></li><li><a href="">Kate Hudson</a></li><li><a href="">Ana Ortiz</a></li><li><a href="">Weight Loss Tips</a></li><li><a href="">Kimberley Locke</a></li></ol><ol start=6><li><a href="">Rod Blagojevich</a></li><li><a href="">2009 Jeep Commander</a></li><li><a href="">Attention Deficit...</a></li><li><a href="">Snoring</a></li><li><a href="">New Orleans Vacations</a></li></ol></div></div></div></div></div></div><div id="footer" class="md"><ul id="flist2"><li class="first"><a href="">Advertise with Us</a></li><li><a href="">Search Marketing</a></li><li><a href="">Privacy Policy</a></li><li><a href="">Terms of Service</a></li><li><a href=r/ad>Suggest a Site</a></li><li><a href="">Yahoo! en Espa&ntilde;ol</a></li><li><a href="">Send Feedback</a></li><li class="last"><a href="">Help</a></li></ul><ul id="copyright"><li class="first">Copyright &copy; 2009 Yahoo! Inc. All rights reserved.</li><li class="first"><a href="">Copyright/IP Policy</a></li><li><a href="">Company Info</a></li><li><a href="">Participate in Research</a></li><li><a href="">Jobs</a></li></ul></div></div> <div id="yblthm_sip" style="display:none"></div></div>
 
<script>
Benchmark.prototype.setup = function() {
    var $1_7_2test = $1_7_2("#test");
    var $gittest = $git("#test");
    $1_7_2test.on("blink", "div.test", $1_7_2.noop);
    $gittest.on("blink", "div.test", $git.noop);
};
</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
1.7.2 trigger
$1_7_2test.trigger("blink");
pending…
git trigger
$gittest.trigger("blink");
pending…
1.7.2 simple match
$1_7_2test.is("div.test");
pending…
git simple match
$gittest.is("div.test");
pending…
1.7.2 pseudo match
$1_7_2test.is("div:first-child");
pending…
git pseudo match
$gittest.is("div:first-child");
pending…
1.7.2 complex pseudo match
$1_7_2test.is("div:first-child:has(#child)");
pending…
git complex pseudo match
$gittest.is("div:first-child:has(#child)");
pending…
1.7.2 element-rooted id
$1_7_2test.find("#child");
pending…
git element-rooted id
$gittest.find("#child");
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment