Commit 85f30051 authored by Benjamin Summerton's avatar Benjamin Summerton

total* works!

parent 1157f1ea
include system/timers
from sequtils import foldl
type
......@@ -28,10 +29,10 @@ proc nsecs*(sw: var Stopwatch): int64 {.inline.}
proc secs*(sw: var Stopwatch): float {.inline.}
# These functions include the time for all laps (plus the current lap, if there is one)
#proc totalNsecs*(sw: var Stopwatch): int64 {.inline.}
##proc totalUsecs*(sw: var Stopwatch): int64 {.inline.}
##proc totalMsecs*(sw var Stopwatch): int64 {.inline.}
#proc totalSecs*(sw: var Stopwatch): float {.inline.}
proc totalNsecs*(sw: var Stopwatch): int64 {.inline.}
#proc totalUsecs*(sw: var Stopwatch): int64 {.inline.}
#proc totalMsecs*(sw var Stopwatch): int64 {.inline.}
proc totalSecs*(sw: var Stopwatch): float {.inline.}
......@@ -100,6 +101,22 @@ proc secs*(sw: var Stopwatch): float =
return sw.nsecs.float / 1_000_000_000.0
# These functions include the time for all laps (plus the current lap, if there is one)
proc totalNsecs*(sw: var Stopwatch): int64 =
let curTicks = getTicks().Nanos
let total = foldl(sw.laps, a + b)
if sw.running:
# Return total + current lap
return (total + (curTicks - sw.startTicks)).int64
else:
return total.int64
proc totalSecs*(sw: var Stopwatch): float =
return sw.totalNsecs.float / 1_000_000_000.0
{.deprecated: [clock: Stopwatch].}
{.deprecated: [nanoseconds: nsecs].}
{.deprecated: [seconds: secs].}
......
......@@ -11,13 +11,16 @@ echo sw.secs
#echo sw.msecs
#echo sw.usecs
#echo sw.nsecs
echo "total=", sw.totalSecs
echo ""
sw.start()
sleep(500)
echo "total=", sw.totalSecs
echo sw.secs
sw.stop()
echo sw.secs
echo "total=", sw.totalSecs
echo ""
......@@ -27,9 +30,13 @@ sleep(100)
echo sw.secs
echo sw.secs
echo sw.secs
echo "total=", sw.totalSecs
echo sw.secs
echo sw.secs
sleep(100)
sw.stop()
echo sw.secs
echo ""
echo "total=", sw.totalSecs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment