jQuery.val vs element.value (v6)

Revision 6 of this benchmark created on


Description

Testing the performance of assignment through $.val() and element.value

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden"><input class="foo" type="hidden">

Setup

var elements = $('.foo');
    var value = Math.random();

Test runner

Ready to run.

Testing in
TestOps/sec
$.val()
elements.val(value);
ready
element.value
for(var i = 0; i < elements.length; ++i) {
    elements[i].value = value;
}
ready

Revisions

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