lama_byterun/stdlib/Timer.lama

25 lines
612 B
Text
Raw Normal View History

2020-08-02 23:56:21 +03:00
-- 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 () {
var t = time ();
2020-08-02 23:56:21 +03:00
fun () {
time () - t
}
}
2020-08-25 16:09:43 +03:00
-- Formats a given time as a floating-point number
public fun toSeconds (t) {
var s = sprintf ("%d", t);
2020-08-25 16:09:43 +03:00
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
}