Can we time a Macro's execution duration?

Hi,

I want to get the time execution of a macro with multiple actions. How can I do this?

Yes, using the ICD Date/Time symbol for milliseconds in day.

At the top of your macro, insert this Action:

%ICUDateTime%A%

At the bottom of your macro, insert these two actions:

START Time:  %TimeStart%
END Time:     %TimeEnd%
DURATION:   %Calculate%(TimeEnd - TimeStart)/1000% sec

I did the math to convert to seconds. Adjust as you desire.

1 Like

@JMichaelTX’s solution is the right idea, but it is generally better to use the function NOW() or SECONDS() functions or rather than %ICUDateTime%A%. For one thing, the ICUDateTime solution would fail if the macro ran past midnight.

SECONDS() gives you the number of fractional seconds since the Mac started, so for timing a duration, it is probably the best bet.

Use Set Variable to Calculation rather than Set Variable to Text to work with functions.

1 Like

Thanks for the correction Peter. That's much better.

Thank you both for your assistance, but I couldn’t get it to give me a calculation for some reason

Hey Ali,

Try this. If it doesn't work then restart the KM engine and editor. If that doesn't work reboot.

-Chris

Calculation Using a Function.kmmacros (2.7 KB)

Uploaded a macro with all the actions, using the SECONDS0 function:

1 Like

Thank you everyone very helpful.

Guys this macro is amazing! however could we develop it so that the result not only provides the duration for the macro to run but the duration for each action in the macro?

Many thanks…

Probably an easy answer here but this is my first variable usage. Loved the solution for this!

How do i get the result to not show so many decimals?

To achieve that, we need to make use of the "Format Results" Option, from the Gear Menu:

and use it in a new KM Action:

Just repeat the calculation before/after each action, and add the results to a KM Variable.

1 Like

Thats a great idea which I am doing. Sometimes I have individual macros with 30 actions across 4/5 different macros. I thought that the more advanced user could benefit from this feature if it was possible as optimising would be much quicker. Thank you for the advise.

Put the set of actions that @JMichaelTX is suggesting into a sub-macro and then it is just an Execute Macro action between each action, perhaps using the Parameter field as some sort of marker.

Something like:

Start:

  • Set variable Start to calculation SECONDS()
  • Set variable Before to calculation Start
  • Set variable Result to “Results are:%Return%”
  • Actions
  • Execute Macro “Mark Time” with parameter “Point A”
  • Actions
  • Execute Macro “Mark Time” with parameter “Point B”
  • Actions
  • Execute Macro “Mark Time” with parameter “Point C”
  • Display Text “%Variable%Result%”

Macro Mark Time looks something like:

  • Set variable Now to calculation SECONDS()
  • Set variable Total to calculation Now - Start format “0.00”
  • Set variable This to calculation Now - Before format “0.00”
  • Set variable Before to calculation Now
  • Set variable Result to “%Variable%Result%%TriggerValue%: %Variable%Total% %Variable%This% %Return%”

Something like that anyway.

1 Like