How to Count Number of Ticks using X++ in AX

Measure execution time of your code

Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.

Measuring is knowing. Before you start changing code, make sure you have a set of data you can keep reusing for your tests. Measure the performance of your code on that data after each change in code so you know the impact of your changes. 

One way to do this is by using the Winapi::getTickCount() (or WinApiServer::getTickCount() if your code runs on server) method.

static void TickCountExample(Args _args)
{
    int ticks;
    ;
    // get the tickcount before the process starts
    ticks = winapi::getTickCount();   
    // start the process
    sleep(2000); // simulate 2 seconds of processing  
    // compare tickcount
    ticks = winapi::getTickCount() - ticks;  
    // display result
    info(strfmt('Number of ticks: %1', ticks));
}


Related Posts

Previous
Next Post »

Thanks for comments.....