7

I'm trying to improve my jQuery performance and I've noticed it runs faster in Chrome than in other browsers. Does it make sense when it is just an AJAX call to a PHP file?

In order to test it, I am doing this on a click event:

var startTime = new Date();

$.post("http://"+ document.domain + "action.json",  { data:  data}, 
    function(dat){

        console.log('ending:  ', (new Date() - startTime) / 1000);
    }
});

Result in seconds are:

  • Chrome 25: 0.148
  • Firefox 19.0.2: 0.212
  • Internet Explorer 9: 0.272
  • Opera 12.14: 0.219

Can the development tools to access the console on each browser interfere in this results?

Thanks.

James Donnelly
  • 126,410
  • 34
  • 208
  • 218
Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • 1
    All browsers have different Javascript engines, and Chromes V8 is probably the fastest for this. Does 0.05 seconds really matter, and how to you intend to optimize the ajax call anyway ? – adeneo Mar 28 '13 at 11:45
  • 3
    Use the network tab in the Developer tools to see the timing broken down in different sections: `DNS Lookup`, `Connecting`, `Sending`, `Waiting`, `Receiving`. I believe Firefox have such measurements as well in some of its developer panels. Then measure the execute of the PHP scrip on the server-side as well. Then you will see where the difference actually is. – Haralan Dobrev Mar 28 '13 at 11:45
  • I am not playing with the DOM. That's why I wonder why a simple call can result in this difference for this simple portion of code. – Alvaro Mar 28 '13 at 11:46
  • 2
    There are so many parameters (JS, browser api, os, network, server) influencing this measurement that I think it hardly is reliable. At least, you cannot optimize much. How many tests did you ran to get those results? – Bergi Mar 28 '13 at 11:48
  • @Bergi, just some tens. I was testing the performance on different browsers and I just noticed there were differences even in this call. – Alvaro Mar 28 '13 at 11:51
  • 3
    @Steve BTW finding an answer to this question would satisfy only your curiosity. The main rule when optimising the performance is to look for the bottlenecks. – Haralan Dobrev Mar 28 '13 at 11:53
  • @HaralanDobrev that's right. I still looking to optimize other things :) – Alvaro Mar 28 '13 at 12:05

1 Answers1

0

I think if you do:

var startTime = new Date();

var a=0;

for(i=0;i<50000;i++){
    a++;
}
console.log('ending:  ', (new Date() - startTime) / 1000);

you will see same difference. Probably it just different javascript parsers.

Narek
  • 3,813
  • 4
  • 42
  • 58