views:

222

answers:

3

I want to try some different options with some javascript (jQuery) to see which is the fastest, however I can't get profiling working properly. Here is the code I want to test.

    $this.keypress(function(e) {
        console.profile("test");

        //retrieve the charcode if possible, otherwise get the keycode
        k = e.which ? e.which : e.CharCode;

        if (blockKeyCodes.indexOf("|" + k + "|") != -1 || e.ctrlKey && k == 86)
            e.preventDefault();

        console.profileEnd();
    });

However, when I run this the console states "no activity to profile". If I use console.time the result is 0ms.

Anyone know how to fix this?

A: 

I think you don't need to specify a name when starting the profile. Alternatively, have you tried console.time?

from http://getfirebug.com/logging

Firebug gives you two easy ways to measure JavaScript performance. The low-fi approach is to call console.time("timing foo") before the code you want to measure, and then console.timeEnd("timing foo") afterwards. Firebug will then log the time that was spent in between.

The high-fi approach is to use the JavaScript profiler. Just call console.profile() before the code you want to measure, and then console.profileEnd() afterwards. Firebug will log a detailed report about how much time was spent in every function call in between.

Jasper De Bruijn
I've tried not specifying a name. As stated above, console.time gives a result of 0ms.
Alistair
A: 

Do you turn on profiling before you run the code?

Click on Firebug > console > profile

You should see a message in firebug saying: "The profiler is running. Click 'Profile' again to see its report."

HTH

DannyLane
I've tried turning on profiling. But if I do this then it starts a new profiler and ends 1 of them, so at the end another is still running.
Alistair
Just so I'm clear.... first you turn on profiling and you get the msg "The profiler is running. Click 'Profile' again to see its report.", then you run your code, and then you press the profile button again? And you dont get a profile report?
DannyLane
My understanding is that you shouldn't need to click 'Profile'. That is what the console.profile() line is for. When I do, the console.profile() line creates another profile, then the console.profileEnd() line closes the profile I made by clicking. So the profile data is the one that I started.Also note clicking profiling starts profiling, but I need to start it in my code to profile an exact piece of code. Or am I missing something?
Alistair
You are right, I put the console.profile/end in my code and it worked. Maybe its an issue with your install? Can you try it on a different machine? Or with different code?
DannyLane
A: 

Firebug profiler does not give the time taken by native methods, wrap entire functionality into a function and call that function between profile start and end.

Amareswar