Commit 8c735ae2 authored by Benjamin Summerton's avatar Benjamin Summerton

Forgot to implement all of `laps()`

parent cfb4b81b
...@@ -179,7 +179,7 @@ proc lap*(sw: var Stopwatch; num: int; incCur: bool = false): int64 = ...@@ -179,7 +179,7 @@ proc lap*(sw: var Stopwatch; num: int; incCur: bool = false): int64 =
## Returns a list of all the recorded laps (in nanoseconds). If `incCur` is set ## Returns a list of all the recorded laps (in nanoseconds). If `incCur` is set
## `true`, then it will include the current lap in the result. By default it is ## `true`, then it will include the current lap in the result. By default it is
## `false`. ## `false`. If no lap is being recored, than `incCur` will be ignored.
## ##
## If you want to convert the returned value to a different time measurement, ## If you want to convert the returned value to a different time measurement,
## use one of the functions: `msecs()`, `usecs()` or `secs()` in conjunction ## use one of the functions: `msecs()`, `usecs()` or `secs()` in conjunction
...@@ -194,9 +194,14 @@ proc lap*(sw: var Stopwatch; num: int; incCur: bool = false): int64 = ...@@ -194,9 +194,14 @@ proc lap*(sw: var Stopwatch; num: int; incCur: bool = false): int64 =
## echo lapsSecs ## echo lapsSecs
## # --> @[1.000117, 0.500115, 0.200212] ## # --> @[1.000117, 0.500115, 0.200212]
proc laps*(sw: var Stopwatch; incCur: bool = false): seq[int64] = proc laps*(sw: var Stopwatch; incCur: bool = false): seq[int64] =
# TODO need to include the current lap too! var
return sw.laps curLap = sw.nsecs
allLaps = sw.laps
if sw.running and incCur:
allLaps.add(curLap)
return allLaps
## Removes a lap from the Stopwatch's record with the given index of `num`. ## Removes a lap from the Stopwatch's record with the given index of `num`.
## This function has the possibility of raising an `IndexError`. ## This function has the possibility of raising an `IndexError`.
......
...@@ -4,10 +4,11 @@ from sequtils import map ...@@ -4,10 +4,11 @@ from sequtils import map
var sw = newStopwatch() var sw = newStopwatch()
echo "laps=", sw.laps(true)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
sw.start() sw.start()
echo "laps=", sw.laps(true)
sleep(1000) sleep(1000)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
sw.stop() sw.stop()
......
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