Commit dc650bea authored by Benjamin Summerton's avatar Benjamin Summerton

Added a case for when there are no laps

parent 85f30051
......@@ -104,7 +104,7 @@ proc secs*(sw: var Stopwatch): float =
# 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)
let total = if sw.laps.len != 0: foldl(sw.laps, a + b) else: 0
if sw.running:
# Return total + current lap
......
......@@ -3,8 +3,11 @@ from os import sleep
var sw = newStopwatch()
echo "total=", sw.totalSecs
sw.start()
sleep(1000)
echo "total=", sw.totalSecs
sw.stop()
echo sw.secs
......
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