|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching • Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
epoch timeUnix and POSIX measure time as the number of seconds that have passed since Thursday 1 January 1970 00:00:00, a point in time known as the Unix epoch. import std/times for i in 1..3: echo epochTime() echo "" echo epochTime().int Sample output: 1779022306.1149607 1779022306.1149895 1779022306.1149921 1779022306 It is a float because sub-second resolution is likely to be supported (depending on the hardware/OS). As can be seen, even in a tight loop the sub-second resolution changes. If you want just the seconds, then convert it to an int. Measure the execution timeimport std/os import std/strformat # &"Hello {name}!" import std/times proc slow() = sleep(2000) # 2 sec. let start = epochTime() slow() let stop = epochTime() # `end` is a keyword echo &"Elapsed time: {stop-start} sec." # Elapsed time: 2.000084400177002 sec. |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |