So I was looking at some code today that had a dow statement. Inside the loop, as you all know, you have to increment the counting variable yourself. So I thought... what if I did this with a for statement and thought about the downto option... so in my testing to see if I need to go downto 1 or 0 I thought that I would do a quick performance test to see if the simpler looking "for" code ran quicker than the more manual "dow" code.
BIG SURPRISE!!!!!
In a test of 100,000,000 iterations the dow loop is 3 times faster than the for loop....
Here's the code... feel free to test it out...
Now, I realize that this is at the mseconds level, but think of all the loops we have in our code...
BIG SURPRISE!!!!!
In a test of 100,000,000 iterations the dow loop is 3 times faster than the for loop....
Here's the code... feel free to test it out...
Code:
dx... d s 10i 0 dy... d s 10i 0 dcounter... d s 10i 0 d d*****************TIMER VARIABLES**************** d starttime... d s z d time_taken... d s 15s 0 d timediff... d s 40a d************************************************ /free *inlr = *on; x = 0; y = 0; counter = 0; starttime = %timestamp(); for x = 100000000 downto 1; endfor; time_taken = %diff(%timestamp():starttime:*MSECONDS); timediff = %char(time_taken); dsply timediff; counter = 0; x = 1; y = 100000000; starttime = %timestamp(); dow x <= y; x+=1; enddo; time_taken = %diff(%timestamp():starttime:*MSECONDS); timediff = %char(time_taken); dsply timediff; /end-free
Comment