Wednesday 25 June 2014

TimeConsumed() function in ax 2012

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 X hours X minutes X seconds. If X is 0 – will not include the value + text.
It handles up to a 24 hour time difference not dependent on start/end time. If time consumed > 24 hours will only report time over 24 hour intervals.

Below is the example:

static void SGX_timeConsumed(Args _args)
{
    FromTime startTime = timeNow();
    int i;
    str dummyStr;
    ;
 
    for (i = 1 ; i <= 500000; i++)
    {
        dummyStr += int2str(i);    
    }
     
    info(strFmt("Total time consumed is  %1", timeConsumed(startTime, timeNow())));
}


static void Milliseconds(Args _args)
{
    TimeInMS        startTime,endTime;
    int i;
    str dummyStr;
    ;
    startTime = WinAPI::getTickCount();

    for (i = 1 ; i <= 500000; i++)
    {
    dummyStr += int2str(i);
    }
    endTime = WinAPI::getTickCount();
    info(strfmt("%1 Milliseconds",endTime-startTime));
}

No comments:

Post a Comment