Javascript run faster if console opened

Viewed 492

i'm developing a phonegap app using a lot of javascript. Now i'm debugging it using Safari Developer Tool, in particular i'm focused on some button that on the device seems to be a bit luggy. So I've added some console.timeEnd() to better understand where the code slow down, but the "problem" is that when i open the console the code start running faster without lag, if i close it again, the lag is back.

Maybe my question is silly but i can't figure it out

Thanks

EDIT: Added the code

function scriviNumeroTastiera(tasto){
        console.time('Funzione ScriviNumeroTastiera');
        contenutoInput = document.getElementById('artInserito').value;
        if ($('#cursoreImg').css('display') == 'none'){
            //$('#cursoreImg').show();

        }
        else if (tasto == 'cancella'){

            //alert(contenutoInput.length);
            if (contenutoInput.length == 0) {

            }
            else {
                indicePerTaglioStringa = (contenutoInput.length)-1;
                contenutoInput = contenutoInput.substr(0, indicePerTaglioStringa);
                $('#artInserito').val(contenutoInput);
                //alert('tastoCanc');
                margineAttualeImg = $('#cursoreImg').css('margin-left');
                indicePerTaglioStringa = margineAttualeImg.indexOf('p');
                margineAttualeImg = margineAttualeImg.substr(0, indicePerTaglioStringa);
                margineAggiornato = parseInt(margineAttualeImg)-20;
                $('#cursoreImg').css('margin-left', margineAggiornato+'px');
            }
        }
        else {
            //contenutoInput = document.getElementById('artInserito').value;
            contenutoAggiornato = contenutoInput+tasto;
            margineAttualeImg = $('#cursoreImg').css('margin-left');
            indicePerTaglioStringa = margineAttualeImg.indexOf('p');
            margineAttualeImg = margineAttualeImg.substr(0, indicePerTaglioStringa);
            margineAggiornato = parseInt(margineAttualeImg)+20;
            $('#cursoreImg').css('margin-left', margineAggiornato+'px');
            $('#artInserito').val(contenutoAggiornato);
        }
        console.timeEnd('Funzione ScriviNumeroTastiera');
    }

The code is a bit crappy, but it's just a beginning ;)

2 Answers
Related