jQuery unwrap vs pure javascript

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="mainmenu"> <a href="#1">1</a>
 <a href="#2">2</a>
 <a href="">3</a>
 <a>4</a>

</div>
    

Preparation code output

<div class="mainmenu"> <a href="#1">1</a> <a href="#2">2</a> <a href="">3</a> <a>4</a> </div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Pure JavaScript
var emptyAnchors = document.querySelectorAll('.mainmenu a:not([href])');
var content = "";
for (var a in emptyAnchors) {
  if(emptyAnchors[a].nodeType==1){
  content = document.createTextNode(emptyAnchors[a].innerHTML);
  emptyAnchors[a].parentNode.insertBefore(content, emptyAnchors[a]);
  emptyAnchors[a].parentNode.removeChild(emptyAnchors[a]);
  }
}
pending…
jQuery unwrap()
$('.mainmenu a:not([href])').contents().unwrap();
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.

0 Comments