home *** CD-ROM | disk | FTP | other *** search
- \ Problem 5.4 Dan Dubrick Set 14D4
-
- \ Rounded percent calculations
- : %R1 ( p n -- m ) 10 */ 5 + 10 / ;
- : %R2 ( p n -- m ) 50 */ 1+ 2/ ;
- : %R3 ( p n -- m ) 100 */MOD SWAP 50 + 100 / + ;
- : %R4 ( p n -- m ) 100 */MOD SWAP 59 > NEGATE + ;
-
- VARIABLE TIME1
- VARIABLE TIME2
- VARIABLE TIME3
- VARIABLE TIME4
-
- \ Timer loop to test all four rounded percent calculations
- : TIME_FOUR ( -- )
- CR ." This is definitely going to take a while, as all four"
- CR ." rounded percent calculations are tested in four loops. "
- TIME-RESET
- 1000 0 DO 1000 0 DO
- \ blank loop
- 15 224 %R1 DROP
- LOOP LOOP
- CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R1 pass."
- TIME-RESET
- 1000 0 DO 1000 0 DO
- \ blank loop
- 15 224 %R2 DROP
- LOOP LOOP
- CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R2 pass."
- TIME-RESET
- 1000 0 DO 1000 0 DO
- \ blank loop
- 15 224 %R3 DROP
- LOOP LOOP
- CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R3 pass."
- TIME-RESET
- 1000 0 DO 1000 0 DO
- \ blank loop
- 15 224 %R4 DROP
- LOOP LOOP
- CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R4 pass."
- CR ;
-
- \ The fastest of the four calculations by the elapsed time is %R4.
-
-