Javascript coding wager I have two scripts written by my co-workers for auto-filling a form with information from the Facebook graph-api. I am trying to figure out which has been coded in a more efficient style?

This is the first one. http://jsfiddle.net/TcGGZ/30/

$('#account_get').click(function(){
    $.getJSON('http://graph.facebook.com/'+$('#facebook').val(), function(fd) {
        $('#id').val(fd.id);
        $('#name').val(fd.name);
        $('#first_name').val(fd.first_name);
        $('#last_name').val(fd.last_name);
        $('#link').val(fd.link);
        $('#username').val(fd.username);
        $('#gender').val(fd.gender);
        $('#locale').val(fd.locale);
    });
});​


This is the second one I am trying to decide about. http://jsfiddle.net/VuY2b/46/

var facebook_account = '';

function fillForm() {
    facebook_account = $('#facebook').val();

    $.getJSON('http://graph.facebook.com/' + facebook_account, function(data) {
        var facebook_data = data;
        console.log(facebook_data);
        var inputs = $('form &gt; input');
        for (var key in facebook_data) {
            for (var l = 0; l &lt; inputs.length; l++) {
                if (inputs[l].getAttribute('name') === key) {
                    inputs[l].value = facebook_data[key];
                }
            }
        }
    });

}

var x = document.getElementById('account_get');
x.addEventListener("click", fillForm, false);​
The first one will be slow because of all the jQuery selection.

The second one will be slow because of the two loops. It keeps looping over what was already found. BUT it is going to be faster than the first one.

I made a basic jSPerf with a basic object: http://jsperf.com/some-random-beef

I also added two more cases to show you faster ways. NOW, if the object contains more junk in it, the results may differ.

var inputs = document.forms[0];
for (var key in fd) {
    var elem = inputs[key];
    if (elem) {
        elem.value = fd[key];
    }       
}


Now what version of the code would I want to read? The first one.