Measure Function Execution Times

By JoeSimmons Last update May 13, 2009 — Installed 3,099 times.

F1 is x times faster than F2

in
Subscribe to F1 is x times faster than F2 4 posts, 2 voices



[disabled] User

Great script, very useful.

One thing I would change: instead of giving you the difference in ms, how about as a multiple?

eg. if

F1: 200ms
F2: 100ms

Instead of

"F2 is 100ms faster than F1"

how about

"F2 is 2.0 times faster than F1"

 
JoeSimmons Script's Author

A good idea but I like to have the exact ms. I also added the execution times of the functions in the alert box.

 
[disabled] User

Well, the reason I suggest this is that whether you run it with 1m loops or 50m loops, the multiple/ratio between the two functions [should] stay (about) the same, providing the true relationship between the two functions. Yet the actual difference in ms between them will vary wildly (say, by *50).

If anybody wants to implement this themselves, just change the end to something like:

if(time_measure_1 < time_measure_2)
  alert("F1 is " + (time_measure_2 / time_measure_1).toFixed(2) + "x faster than F2");
else
  alert("F2 is " + (time_measure_1 / time_measure_2).toFixed(2) + "x faster than F1");

 
JoeSimmons Script's Author

Yeah. I do like the idea but I have to have the times in ms there too. Maybe I can add the ratio as another line on the alert box.
Edit: There I added "(***x)" right after the ms time, so it will look like Function 1 is 3,023 ms (1.08x) faster than Function 2.

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel