midrange.com code scratchpad |
Name:
DOW vs FOR loop performance test.
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
06/23/2011 12:57:19 pm
|
IP:
Logged
|
|
Description:
This test illustrates that the FOR loop is 3x slower to execute than a DOW loop.
|
Code:
- dx...
- d s 10i 0
- dy...
- d s 10i 0
- dz...
- d s 10i 0
- diters...
- d s 10i 0 inz(100000000)
-
- d*****************TIMER VARIABLES****************
- d starttime...
- d s z
- d time_taken...
- d s 15s 0
- d timediff...
- d s 40a
- d************************************************
- /free
- *inlr = *on;
- //**************************************************//
- //Test how many iterations happen in For x downto 0
- //and dow x <= y and see if the results are x or x+1
- //
- x = 0;
- y = 0;
- z = 0;
- starttime = %timestamp();
- for x = iters downto 1;
- endfor;
- time_taken = %diff(%timestamp():starttime:*MSECONDS);
- timediff = 'FOR DOWNTO: ' + %char(time_taken);
-
- dsply timediff;
-
-
- starttime = %timestamp();
- for x = 1 to iters;
- endfor;
- time_taken = %diff(%timestamp():starttime:*MSECONDS);
- timediff = 'FOR TO: ' + %char(time_taken);
- dsply timediff;
-
- x = 1;
- y = iters;
-
- starttime = %timestamp();
- dow x <= y;
- x+=1;
- enddo;
- time_taken = %diff(%timestamp():starttime:*MSECONDS);
- timediff = 'DOW: ' + %char(time_taken);
- dsply timediff;
- /end-free
-
|
|
|