jQuery.val vs element.value (v12)

Revision 12 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 id="foo" type="hidden">
<input id="get" type="hidden" value="somevalue" />

Setup

var value = Math.random();
    var $el = $('#foo');
    var el = document.getElementById('foo');
    var $get = $('#get');

Test runner

Ready to run.

Testing in
TestOps/sec
$.val()
$('#foo').val(value);
ready
$.value
$('#foo').value = value;
ready
$el.value
$el[0].value = value;
ready
Native.value
document.getElementById('foo').value = value;
ready
el.value
el.value = value;
ready
$.val() get
var value = $get.val();
ready
$el.value get
var value = $get[0].value;
ready

Revisions

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