mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
25 lines
No EOL
616 B
Text
25 lines
No EOL
616 B
Text
-- Timer.
|
|
-- (C) Dmitry Boulytchev, JetBrains Research, St. Petersburg State University, 2020
|
|
--
|
|
-- This unit provides an implementation for simple timer. A timer is a function which
|
|
-- measures an elapsed time (in microseconds) since its creation.
|
|
|
|
-- Creates a new timer
|
|
public fun timer () {
|
|
local t = time ();
|
|
|
|
fun () {
|
|
time () - t
|
|
}
|
|
}
|
|
|
|
-- Formats a given time as a floating-point number
|
|
public fun toSeconds (t) {
|
|
local s = sprintf ("%d", t);
|
|
|
|
if s.length >= 7
|
|
then
|
|
sprintf ("%s.%s", substring (s, 0, s.length - 7 + 1), substring (s, s.length - 7 + 1, 6))
|
|
else sprintf ("0.%s", s)
|
|
fi
|
|
} |