Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

Programming 1 (BI)
  ▸ exercises
  ▸ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ✦C++, ✦Clojure, ✦Scala


[ edit | logout ]
[ sandbox | passwd ]

epoch time

Unix 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 time

import 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.
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 May 19, 12:43