jquery id-selector vs variable

Benchmark created by Eugene on


Preparation HTML

<div id="test">Some text here</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var test = '';

Teardown


    $('#test').text('Some text here');
  

Test runner

Ready to run.

Testing in
TestOps/sec
Element by id
$('#test').text($('#test').text()+' more text');
$('#test').text($('#test').text()+' and even more text');
$('#test').text($('#test').text()+' and more');
$('#test').hide();
$('#test').show();
$('#test').fadeOut();
$('#test').fadeIn();
 
ready
variable
test = $('#test');
test.text(test.text()+' more text');
test.text(test.text()+' and even more text');
test.text(test.text()+' and more');
test.hide();
test.show();
test.fadeOut();
test.fadeIn();
 
ready

Revisions

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

  • Revision 1: published by Eugene on