views:

68

answers:

3

I was simply wondering what methods folks are using to test their javascript's execution speed and look out for performance bottlenecks, whether they simply be code snippets or services.

I'd also like to know why you would advocate this method. Flexibility? Simplicity? Or perhaps there is a single, right way. Whatever it is, I'm looking for the best method to use and why you'd argue it as such.

(Perhaps this is a question that should be a community wiki? Or just altogether inappropriate as being too subjective? But I'm searching for well-articulated examples that illustrate why certain options would be used, and I will mark the best answer accordingly.)

+2  A: 

JSPerf.com is a nice site for JS benchmarking. It's used more for benchmarking different methodologies rather than pieces of your own code (but nothing is stopping you from using it to benchmark your code).

CD Sanchez
Daniel, very interesting. I'm going to go ahead and vote this up because it'd be a great way to test, say, various ways of doing the same thing in jQuery. I'm still definitely looking for a way to do this within applications, though.
Joshua Cody
+1  A: 

There's a SO discussion on this that I think you will find useful: http://stackoverflow.com/questions/111368/how-do-you-performance-test-javascript-code.

I just started playing with Firebug's Profiler and it looks pretty slick. Try that out and maybe it's what you're looking for.

You could also try using console.time and console.timeEnd in your js. It'll look something like this:

console.time('yourTimer');

$('.some-div').hover(function() {
    $(this).slideUp();
}, function() {
    $(this).slideDown();
});

console.timeEnd('yourTimer');
Koes Bong
A: 

timer.js. It's just a simple timer, but on Google Chrome, you get microsecond resolution instead of normal JavaScript millisecond resolution.

Eli Grey
Very nice, I don't think I likely need this level of precision, but it's good to know it exists should that ever change. Thanks!
Joshua Cody