jquery text method vs native innertext property

Benchmark created on


Preparation HTML

<nav>
<a>menu item 1</a>
<a>menu item 2</a>
<a>menu item 3</a>
<a>menu item 4</a>
<a>menu item 5</a>
</nav>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var $nav_items = $('nav>a');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jquery text method
$nav_items.each(function(){
 var $this = $(this);
 $this.text($this.text().replace('nav item ','asdf'));
});
ready
native innertext property
i=$nav_items.length;
while(i>0){
 $nav_items[i].innerText = $nav_items[i].innerText.replace('nav item ','asdf');
 --i;
}
ready

Revisions

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