jQuery.val vs element.value

Benchmark created on


Preparation HTML

<script src="https://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.