How to resolve the algorithm System time step by step in the Forth programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm System time step by step in the Forth programming language
Table of Contents
Problem Statement
Output the system time (any units will do as long as they are noted) either by a system command or one built into the language. The system time can be used for debugging, network information, random number seeds, or something as simple as program performance.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm System time step by step in the Forth programming language
Source code in the forth programming language
[UNDEFINED] MS@ [IF] \ Win32Forth (rolls over daily)
[DEFINED] ?MS [IF] ( -- ms )
: ms@ ?MS ; \ iForth
[ELSE] [DEFINED] cputime [IF] ( -- Dusec )
: ms@ cputime d+ 1000 um/mod nip ; \ gforth: Anton Ertl
[ELSE] [DEFINED] timer@ [IF] ( -- Dusec )
: ms@ timer@ >us 1000 um/mod nip ; \ bigForth
[ELSE] [DEFINED] gettimeofday [IF] ( -- usec sec )
: ms@ gettimeofday 1000 MOD 1000 * SWAP 1000 / + ; \ PFE
[ELSE] [DEFINED] counter [IF]
: ms@ counter ; \ SwiftForth
[ELSE] [DEFINED] GetTickCount [IF]
: ms@ GetTickCount ; \ VFX Forth
[ELSE] [DEFINED] MICROSECS [IF]
: ms@ microsecs 1000 UM/MOD nip ; \ MacForth
[THEN] [THEN] [THEN] [THEN] [THEN] [THEN] [THEN]
MS@ . \ print millisecond counter
You may also check:How to resolve the algorithm Binary strings step by step in the Phix programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the Arturo programming language
You may also check:How to resolve the algorithm Long year step by step in the Python programming language
You may also check:How to resolve the algorithm Tree traversal step by step in the D programming language
You may also check:How to resolve the algorithm Even or odd step by step in the bc programming language