Measure Execution Time

There are situations where you would like to know the duration of execution of an AIMMS code-block. In AIMMS Developer, you can do this easily by using the built-in Profiler, accessed through Tools -> Diagnostic Tools -> Profiler. This profiler will provide you with information about how long each statement in an execution took, as well as how long the evaluation of the definition of a parameter took. More information about the profiler can be found in The AIMMS profiler.

You can also start the profiler using the function ProfilerStart(). It is common to make a call to this function in the initialization procedures so that you can always have the profiler available while developing an AIMMS application.

In addition, you can query the profiler using the procedure ProfilerCollectAllData().

See also

See all related functions related to Profiler in AIMMS Function Reference - Development Support.

However, using the AIMMS Profiler has two rather minor disadvantages when measuring execution time:

  1. The AIMMS Profiler cannot be active when the AIMMS Debugger is active.

  2. The AIMMS Profiler does not support directly the measuring of a code fragment, or the measuring of a piece of code executed when some condition is true.

When fine control of measured execution time is needed, the time functions of AIMMS can be used. Based on those functions a Stopwatch Library was created, more details and download here.

Example

The Stopwatch Library is used on Traveling Salesman to measure the execution time of each type of solve. The Traveling Salesman procedures that use stopwatch functions are:

  • pr_findInitialTour

  • pr_improveTourCyclic

  • pr_improveTourSimultaneous

  • pr_solveModel

  • pr_solveRelaxedModel

And the method to use is simple:

1stopwatch::pr_start() ;
2
3! Any code
4
5p_elapsedTime := stopwatch::fnc_elapsed();