There are situations where you would like to know how long the execution of something in AIMMS took.
When you are working as an AIMMS developer, one of the tools you have for this is the AIMMS 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 chapter “Debugging and Profiling an AIMMS Model” in the AIMMS User’s Guide.
When running in End-user mode, the profiler is not available. To still be able to give the end-user feedback on how much time certain steps took, you can create a ‘stopwatch’ in AIMMS code. This can be achieved by introducing the following identifiers into your model:
QUANTITY: identifier : SI_Time_Duration base unit : s conversions : tick -> s : # -> # / 100 comment : "Expresses the value for the duration of periods." ; STRING PARAMETER: identifier : StartTime comment : "Time the stopwatch was started" ; PARAMETER: identifier : ElapsedTime unit : s comment : "Time that has elapsed since the stopwatch was started. The value for this is updated by the StopStopwatch procedure"; PROCEDURE identifier : StartStopwatch comment : "Set the starttime of the stopwatch" body : !Use the CurrentToString AIMMS function to store the current time !in YYYY-MM-DD HH:MM:SS:TT format StartTime := CurrentToString( "%c%y-%m-%d %H:%M:%S:%t"); ENDPROCEDURE ; PROCEDURE identifier : StopStopwatch comment : "Deterine how many ticks have elapsed since the start of the stopwatch" body : !Using the CurrentToMoment AIMMS function, we can ask for the number !of ticks that have elapsed at the moment since the given StartTime !(which was stored by calling the StartStopwatch procedure). !Please note that we do not actually 'stop' the stopwatch, but only !store the time elapsed. ElapsedTime := CurrentToMoment( [tick], StartTime ); ENDPROCEDURE ;
If your model already contains the SI_Time quantity, just make sure that the units second and tick (1/100th of one second) are defined (either as conversion, or as base unit).
You can download the above code as an aim file from the link below. Please see the instructions in the post Exporting a section and importing it in another AIMMS project to import this aim file into your own project. If your project already contains the SI_Time quantity, please remove the quantity from the aim file after downloading it.
After you have imported the section, the stopwatch code can be used as follows:
StartStopwatch ; SomeLongLastingProcedure ; StopStopwatch ; DialogMessage(formatstring("Execution of procedure took %n seconds" , ElapsedTime) ) ;
When running this code, you will get a dialog window telling you how many seconds the execution of SomeLongLastingProcedure took.