...
 
Commits (3)
...@@ -78,7 +78,7 @@ template bench*(sw: Stopwatch; body: untyped): untyped = ...@@ -78,7 +78,7 @@ template bench*(sw: Stopwatch; body: untyped): untyped =
#== Internal Procs ==# #== Internal Procs ==#
#====================# #====================#
# This needs to choose a different getTicks_internal() function depending upon # This needs to choose a different getTicks_internal() function depending upon
# the target platform. # the target platform.
proc getTicks_internal(): Ticks = proc getTicks_internal(): Ticks =
{.emit: ["return performance.now();"].} {.emit: ["return performance.now();"].}
...@@ -109,7 +109,7 @@ proc stopwatch*(enableLapping:bool): Stopwatch = ...@@ -109,7 +109,7 @@ proc stopwatch*(enableLapping:bool): Stopwatch =
startTicks: 0.Ticks, startTicks: 0.Ticks,
recordLaps: enableLapping, recordLaps: enableLapping,
previousLap: 0.Ticks, previousLap: 0.Ticks,
laps: if enableLapping: @[] else: nil, laps: @[],
total: 0 total: 0
) )
...@@ -345,4 +345,3 @@ proc totalMsecs*(sw: var Stopwatch): int = ...@@ -345,4 +345,3 @@ proc totalMsecs*(sw: var Stopwatch): int =
## float). ## float).
proc totalSecs*(sw: var Stopwatch): float = proc totalSecs*(sw: var Stopwatch): float =
return secs(sw.totalMsecs) return secs(sw.totalMsecs)
...@@ -84,7 +84,7 @@ template bench*(sw: Stopwatch; body: untyped): untyped = ...@@ -84,7 +84,7 @@ template bench*(sw: Stopwatch; body: untyped): untyped =
#== Internal Procs ==# #== Internal Procs ==#
#====================# #====================#
# This needs to choose a different getTicks_internal() function depending upon # This needs to choose a different getTicks_internal() function depending upon
# the target platform. # the target platform.
when defined(js) and not defined(nodejs): when defined(js) and not defined(nodejs):
# For browser JS # For browser JS
...@@ -100,12 +100,12 @@ elif defined(macosx): ...@@ -100,12 +100,12 @@ elif defined(macosx):
# For OS X # For OS X
from times import epochTime from times import epochTime
proc getTicks_internal(): Ticks= proc getTicks_internal(): Ticks=
return (epochTime() * 1_000_000_000).Ticks return (epochTime() * 1_000_000_000).Ticks
else: else:
# For Linux & Windows # For Linux & Windows
proc getTicks_internal(): Ticks= proc getTicks_internal(): Ticks=
return getTicks() return getTicks()
...@@ -143,7 +143,7 @@ proc stopwatch*(enableLapping:bool): Stopwatch = ...@@ -143,7 +143,7 @@ proc stopwatch*(enableLapping:bool): Stopwatch =
startTicks: 0.Ticks, startTicks: 0.Ticks,
recordLaps: enableLapping, recordLaps: enableLapping,
previousLap: 0.Ticks, previousLap: 0.Ticks,
laps: if enableLapping: @[] else: nil, laps: @[],
total: 0 total: 0
) )
...@@ -415,4 +415,3 @@ proc totalMsecs*(sw: var Stopwatch): int64 = ...@@ -415,4 +415,3 @@ proc totalMsecs*(sw: var Stopwatch): int64 =
## See also: `totalNsecs()`, `totalUsecs()`, `totalMsecs()` ## See also: `totalNsecs()`, `totalUsecs()`, `totalMsecs()`
proc totalSecs*(sw: var Stopwatch): float = proc totalSecs*(sw: var Stopwatch): float =
return secs(sw.totalNsecs) return secs(sw.totalNsecs)
...@@ -3,7 +3,7 @@ from sequtils import map ...@@ -3,7 +3,7 @@ from sequtils import map
# Choose where to get the "sleep" function from # Choose where to get the "sleep" function from
when defined(js): when defined(js):
# NOTE: This isn't giving me the result I want... # NOTE: This isn't giving me the result I want...
proc sleep(ms: int) = proc sleep(ms: int) =
{.emit: ["return new Promise(resolve => setTimeout(resolve,", ms, "));"].} {.emit: ["return new Promise(resolve => setTimeout(resolve,", ms, "));"].}
...@@ -24,26 +24,26 @@ var ...@@ -24,26 +24,26 @@ var
proc test() = proc test() =
# Print a message # Print a message
echo "Testing with laps ", (if recordLaps: "on." else: "off.") echo "Testing with laps ", (if recordLaps: "on." else: "off.")
# Init the stopwatch and go # Init the stopwatch and go
sw = stopwatch(recordLaps) sw = stopwatch(recordLaps)
echo "laps=", sw.laps(true) echo "laps=", sw.laps(true)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
sw.start() sw.start()
echo "laps=", sw.laps(true) echo "laps=", sw.laps(true)
sleep(1000) sleep(1000)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
sw.stop() sw.stop()
echo sw.secs echo sw.secs
#echo sw.msecs #echo sw.msecs
#echo sw.usecs #echo sw.usecs
#echo sw.nsecs #echo sw.nsecs
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
echo "" echo ""
sw.start() sw.start()
sleep(500) sleep(500)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
...@@ -52,7 +52,7 @@ proc test() = ...@@ -52,7 +52,7 @@ proc test() =
echo sw.secs echo sw.secs
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
echo "" echo ""
sw.start() sw.start()
echo sw.secs echo sw.secs
sleep(100) sleep(100)
...@@ -69,9 +69,9 @@ proc test() = ...@@ -69,9 +69,9 @@ proc test() =
echo sw.secs echo sw.secs
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
echo "" echo ""
var sw2 = sw.clone() var sw2 = sw.clone()
echo "lapCount=", sw.numLaps echo "lapCount=", sw.numLaps
echo "L1=", sw.lap(0).secs echo "L1=", sw.lap(0).secs
echo "L2=", if sw.isRecordingLaps: sw.laps()[1].secs else: 0 echo "L2=", if sw.isRecordingLaps: sw.laps()[1].secs else: 0
...@@ -80,12 +80,12 @@ proc test() = ...@@ -80,12 +80,12 @@ proc test() =
echo "lapCount=", sw.numLaps echo "lapCount=", sw.numLaps
echo "----" echo "----"
echo "lapCount=", sw2.numLaps echo "lapCount=", sw2.numLaps
var lapsSecs = sw2.laps().map(proc(x: int64): float = secs(x)) var lapsSecs = sw2.laps().map(proc(x: int64): float = secs(x))
echo "all laps(s)=", lapsSecs echo "all laps(s)=", lapsSecs
echo "" echo ""
sw.reset() sw.reset()
echo "lapCount=", sw.numLaps echo "lapCount=", sw.numLaps
sw.start() sw.start()
...@@ -99,10 +99,10 @@ proc test() = ...@@ -99,10 +99,10 @@ proc test() =
echo "total(u)=", sw.totalUsecs echo "total(u)=", sw.totalUsecs
echo "total(n)=", sw.totalNsecs echo "total(n)=", sw.totalNsecs
echo "" echo ""
bench(sw, sleep(1000)) bench(sw, sleep(1000))
echo "bench(sleep(1000))=", sw.secs echo "bench(sleep(1000))=", sw.secs
# Test with laps or no laps via an argument (non-js only) # Test with laps or no laps via an argument (non-js only)
...@@ -119,5 +119,3 @@ else: ...@@ -119,5 +119,3 @@ else:
recordLaps = false recordLaps = false
test() test()
...@@ -23,23 +23,23 @@ proc test() = ...@@ -23,23 +23,23 @@ proc test() =
# Print a message # Print a message
echo "Testing with laps ", (if recordLaps: "on." else: "off.") echo "Testing with laps ", (if recordLaps: "on." else: "off.")
# Init the stopwatch and go # Init the stopwatch and go
sw = stopwatch(recordLaps) sw = stopwatch(recordLaps)
echo "laps=", sw.laps(true) echo "laps=", sw.laps(true)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
sw.start() sw.start()
echo "laps=", sw.laps(true) echo "laps=", sw.laps(true)
sleep(1000) sleep(1000)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
sw.stop() sw.stop()
echo sw.secs echo sw.secs
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
echo "" echo ""
sw.start() sw.start()
sleep(500) sleep(500)
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
...@@ -48,7 +48,7 @@ proc test() = ...@@ -48,7 +48,7 @@ proc test() =
echo sw.secs echo sw.secs
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
echo "" echo ""
sw.start() sw.start()
echo sw.secs echo sw.secs
sleep(100) sleep(100)
...@@ -63,9 +63,9 @@ proc test() = ...@@ -63,9 +63,9 @@ proc test() =
echo sw.secs echo sw.secs
echo "total=", sw.totalSecs echo "total=", sw.totalSecs
echo "" echo ""
var sw2 = sw.clone() var sw2 = sw.clone()
echo "lapCount=", sw.numLaps echo "lapCount=", sw.numLaps
echo "L1=", sw.lap(0).secs echo "L1=", sw.lap(0).secs
echo "L2=", if sw.isRecordingLaps: sw.laps()[1].secs else: 0 echo "L2=", if sw.isRecordingLaps: sw.laps()[1].secs else: 0
...@@ -74,12 +74,12 @@ proc test() = ...@@ -74,12 +74,12 @@ proc test() =
echo "lapCount=", sw.numLaps echo "lapCount=", sw.numLaps
echo "----" echo "----"
echo "lapCount=", sw2.numLaps echo "lapCount=", sw2.numLaps
var lapsSecs = sw2.laps().map(proc(x: int): float = secs(x)) var lapsSecs = sw2.laps().map(proc(x: int): float = secs(x))
echo "all laps(s)=", lapsSecs echo "all laps(s)=", lapsSecs
echo "" echo ""
sw.reset() sw.reset()
echo "lapCount=", sw.numLaps echo "lapCount=", sw.numLaps
sw.start() sw.start()
...@@ -91,10 +91,10 @@ proc test() = ...@@ -91,10 +91,10 @@ proc test() =
echo "total(s)=", sw.totalSecs echo "total(s)=", sw.totalSecs
echo "total(m)=", sw.totalMsecs echo "total(m)=", sw.totalMsecs
echo "" echo ""
bench(sw, sleep(1000)) bench(sw, sleep(1000))
echo "bench(sleep(1000))=", sw.secs echo "bench(sleep(1000))=", sw.secs
# Call test inside body.onload for browser JS # Call test inside body.onload for browser JS
......