Home

Monday, June 20, 2016

timeConsumed()–a very useful function in Global class in AX 2012 [x++]

There is a very useful function timeConsumed() in Global class which we can use to calculate the time taken to execute business logic in AX 2012.
This function will return time consumed string in the form of XX hours XX minutes XX seconds (00:00:00). It handles up to a 24 hour time difference not dependent on start/end time. 

Limitation: If time consumed is greater then 24 hours will only report time over 24 hour intervals.
Code: 
static void DemoTimeConsumed(Args _args)
{
    FromTime startTime = timeNow();
    int i;
    str res;
    ;
   
    for (i = 1 ; i <= 500000; i++)
    {
        res+= int2str(i);     
    }
       
    info(strFmt("Total time consumed with this operation is  %1", timeConsumed(startTime, timeNow())));
}

No comments:

Post a Comment