how-to-chain-this-code [stackoverflow №16009101]

JavaScript performance comparison

Test case created by vladimir77

Info

See http://stackoverflow.com/questions/16009101/how-to-chain-this-code/16054850#16054850

Preparation code

<script src="http://code.jquery.com/jquery-1.8.3.min.js">
</script>
<p style="background:#00FF66">#1 p-inner-first</p>
<div style="background:#00FF66">#2 div-first</div>
<p style="background:#00FF66">#3 p-inner-second</p>    
 
<div>
    <p style="background:#FF6633">#4 p-inner-third</p>
    <div id="test" style="background:#FF6633">#5 div-second</div>
    <p style="background:#FF6633">#6 p-inner-fourth</p>
    <div style="background:#00FF66"><p>#7 hello</p></div>
</div>  

<p style="background:#00FF66">#8 p-inner-fifth</p>
<div style="background:#00FF66">#9 div-third</div>
<p style="background:#00FF66">#10 p-inner-sixth</p>

Preparation code output

#1 p-inner-first

#2 div-first

#3 p-inner-second

#4 p-inner-third

#5 div-second

#6 p-inner-fourth

#7 hello

#8 p-inner-fifth

#9 div-third

#10 p-inner-sixth

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
origin
$("#test").siblings('p').remove();
$("#test").remove();
pending…
addBack
$("#test").siblings('p').addBack().remove();
pending…
andSelf
$("#test").siblings('p').andSelf().remove();
pending…
end
$("#test").siblings('p').remove().end().remove();
pending…
my decision
$("#test, > p", $('#test').parent()).remove();
pending…
my previous/incorrect decision
$("#test, #test ~ p").remove();
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