tester.nim 1.29 KB
Newer Older
1 2
import stopwatch
from os import sleep
3 4
from sequtils import map

5

Benjamin Summerton's avatar
Benjamin Summerton committed
6
var sw = newStopwatch()
7
echo "laps=", sw.laps(true)
8

9
echo "total=", sw.totalSecs
Benjamin Summerton's avatar
Benjamin Summerton committed
10
sw.start()
11
echo "laps=", sw.laps(true)
12
sleep(1000)
13
echo "total=", sw.totalSecs
Benjamin Summerton's avatar
Benjamin Summerton committed
14
sw.stop()
15 16 17 18

echo sw.secs
#echo sw.msecs
#echo sw.usecs
Benjamin Summerton's avatar
Benjamin Summerton committed
19
#echo sw.nsecs
Benjamin Summerton's avatar
Benjamin Summerton committed
20
echo "total=", sw.totalSecs
21
echo ""
Benjamin Summerton's avatar
Benjamin Summerton committed
22 23 24

sw.start()
sleep(500)
Benjamin Summerton's avatar
Benjamin Summerton committed
25
echo "total=", sw.totalSecs
Benjamin Summerton's avatar
Benjamin Summerton committed
26 27 28
echo sw.secs
sw.stop()
echo sw.secs
Benjamin Summerton's avatar
Benjamin Summerton committed
29
echo "total=", sw.totalSecs
30 31 32 33 34 35 36 37
echo ""

sw.start()
echo sw.secs
sleep(100)
echo sw.secs
echo sw.secs
echo sw.secs
Benjamin Summerton's avatar
Benjamin Summerton committed
38
echo "total=", sw.totalSecs
39 40
echo "lapCount=", sw.numLaps(false)
echo "lapCount=", sw.numLaps(true)
41 42 43 44 45
echo sw.secs
echo sw.secs
sleep(100)
sw.stop()
echo sw.secs
46
echo "total=", sw.totalSecs
Benjamin Summerton's avatar
Benjamin Summerton committed
47 48
echo ""

49 50 51 52 53 54 55 56 57 58
var sw2 = sw.clone()

echo "lapCount=", sw.numLaps
echo "L1=", sw.lap(0).secs
echo "L2=", sw.laps[1].secs
sw.rmLap(0)
echo "all laps=", sw.laps
echo "lapCount=", sw.numLaps
echo "----"
echo "lapCount=", sw2.numLaps
59 60 61 62

var lapsSecs = sw2.laps.map(proc(x: int64): float = secs(x))

echo "all laps(s)=", lapsSecs
63 64
echo ""

65
sw.reset()
66
echo "lapCount=", sw.numLaps
67 68 69 70 71 72
sw.start()
sleep(10)
echo "total=", sw.totalSecs
sw.restart()
echo "total=", sw.totalSecs
sleep(250)
73 74 75 76
echo "total(s)=", sw.totalSecs
echo "total(m)=", sw.totalMsecs
echo "total(u)=", sw.totalUsecs
echo "total(n)=", sw.totalNsecs
77
echo ""
78