\ Keeping track of Time \ Study timers provided using gforth - Mac OSX (PowerBook G4) vocabulary test test definitions : runtime-test ( -- ) page 0 3 at-xy ." time t2-t1 max min .s ratio" 0. 0. { D: utime0 D: utime1 } 0. 0. { D: usertime0 D: usertime1 } 0. 0. { D: systime0 D: systime1 } 0. 10000000000. { D: utmax D: utmin } 0. 10000000000. { D: usermax D: usermin } 0. 10000000000. { D: sysmax D: sysmin } begin \ permanent display times utime ( -- dutime ) to utime0 cputime ( -- duser0 dsystem0 ) to systime0 to usertime0 1000000 for ( insert testword here ) next cputime ( -- duser1 dsystem1 ) to systime1 to usertime1 utime ( -- dutime ) to utime1 \ formatted display of times cr 0 0 at-xy ." user: " usertime0 20 ud.r usertime1 usertime0 d- 2dup usermax d> if 2dup to usermax then 2dup usermin d< if 2dup to usermin then 10 ud.r usermax 10 ud.r usermin 10 ud.r space .s usermin d>f usermax d>f f/ f. cr 0 1 at-xy ." sys : " systime0 20 ud.r systime1 systime0 d- 2dup sysmax d> if 2dup to sysmax then 2dup sysmin d< if 2dup to sysmin then 10 ud.r sysmax 10 ud.r sysmin 10 ud.r space .s sysmin d>f sysmax d>f f/ f. cr 0 2 at-xy ." ut : " utime0 20 ud.r utime1 utime0 d- 2dup utmax d> if 2dup to utmax then 2dup utmin d< if 2dup to utmin then 10 ud.r utmax 10 ud.r utmin 10 ud.r space .s utmin d>f utmax d>f f/ f. key? until 0 5 at-xy ; \ Brian Fox in 2008 \ Elapsed timer for gforth compatible with Win32Forth : ms@ ( -- n ) utime drop 1000 / ; 0 value start-time : timer-reset ( -- ) ms@ to start-time ; : .#" ( n1 n2 -- a1 n3 ) >r 0 <# r> 0 ?do # loop #> ; : .elapsed ( -- ) ." Elapsed time: " ms@ start-time - 1000 /mod 60 /mod 60 /mod 2 .#" type ." :" 2 .#" type ." :" 2 .#" type ." ." 3 .#" type ; : elapse ( -- ) timer-reset interpret cr .elapsed ; 0 [if] ----- Gforth 0.6.2, Copyright (C) 1995-2003 Free Software Foundation, Inc. Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license' Type `bye' to exit include elapsed.fs ok ok elapse 5000 ms Elapsed time: 00:00:05.000 ok elapse 10000 ms Elapsed time: 00:00:10.001 ok ----- Brian Fox [then] : .. bye ; words cr cr