2

When I want to figure out how fast my JavaScript is I usually resort to "estimating" how fast it appears to be, this is extremely inefficient and most times I'm outright wrong.

In Ubuntu when you want to tell how long a program took to run, you'd use the time command like this:

time script_name.py

The output would look like this:

program output....

real    0m0.123s
user    0m0.123s
sys     0m0.123s

How can I get FireFox to show me similar information in the browser console?

NOTE: I'm using the latest version of FireFox & Lubuntu 18.04 (LTS).

Malekai
  • 4,765
  • 5
  • 25
  • 60
  • Noted, thanks for the heads up. – Malekai Mar 26 '19 at 08:27
  • 1
    Note that Firefox specifically **does not optimize** code ran from the dev-tools js console. Do not measure function performance from there, always do in real conditions, that is from your own page. – Kaiido Mar 26 '19 at 08:29

1 Answers1

3

Various options for you.

  1. You can put

    console.time("program");
    

    at the beginning and

    console.timeEnd("program");
    

    at the end. It'll tell you the elapsed time between those two calls.

  2. If you're looking for the relative performance of two fairly smallish code snippets, there are various online tools that will do that for you (https://jsperf.com, http://jsben.ch).

  3. If the code doesn't involve browser-specific things, you can use Node.js in your terminal to run your code, and use time on it as usual.

    None of the above is specific to Firefox.

  4. In the Firefox dev tools specifically, there's a Performance tab you can use to measure performance of specific things in a web page. This page on mozilla.org covers it.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Thank you for taking the time to answer my question, I've tried the first three recommendations, and they all work as expected, thank you! – Malekai Mar 26 '19 at 08:24
  • 1
    https://developer.mozilla.org/en-US/docs/Mozilla/Performance/Profiling_with_the_Built-in_Profiler try this too – deviprsd Mar 26 '19 at 08:27