The Infolog

A blog of Dynamics AX development tips and tricks

Skip to: Content | Sidebar | Footer

Adding to a container with += vs. ConIns()

29 September, 2013 (01:25) | Dynamics AX | By: Howard Webb

While adding data to the end of a container there can be large savings by using += rather than ConIns. Try the code below and compare the results:

 

static void Containertest(Args _args)

{

int                            ticks;

Container                con;

Random                  random = new Random();

int                            myrandom;

int                            i;

;

 

//Start on ins

ticks = WinApi::getTickCount();

for(i = 1; i <= 100000; i++)

{

myrandom = random.nextInt();

con = conins(con, i, myrandom);

}

ticks = WinAPI::getTickCount() – ticks;

info(strfmt(“Time taken via ConIns: %1”, ticks));

 

//Start on +=

ticks = WinApi::getTickCount();

for(i = 1; i <= 100000; i++)

{

myrandom = random.nextInt();

con += myrandom;

}

ticks = WinAPI::getTickCount() – ticks;

info(strfmt(“Time taken via +=: %1”, ticks));

}