.after() vs jQuery .insertAfter() vs parentNode.insertBefore()

JavaScript performance comparison

Test case created by Binyamin

Info

jQuery .after() vs jQuery .insertAfter() vs parentNode.insertBefore()

Preparation code

<div id=container>
    <div id=header>1. header</div>
    <div id=content>3. content</div>
    <div id=thumbnails>2. thumbnails</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Preparation code output

3. content
2. thumbnails

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.after()
$('#header').after($('#thumbnails'));
pending…
.insertAfter()
$('#thumbnails').insertAfter($('#header'));
pending…
parentNode.insertBefore()
var thumb = document.getElementById('thumbnails'),
    cont = document.getElementById('content');
thumb.parentNode.insertBefore(thumb, cont);
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