Skip to content

Commit

Permalink
testOnce with name param
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Nov 5, 2019
1 parent a8a03d7 commit cd73891
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ m.finish()
```
You can also monit once as follows:
```nim
timeOnce:
timeOnce("test-once"):
var a = 12
for i in 1 .. 10000:
a += i
Expand Down
20 changes: 10 additions & 10 deletions src/timeitpkg/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,24 @@ template timeGo*(myFunc: untyped,
timer


template timeOnce*(code: untyped) =
var m = monit("test-once")
template timeOnce*(name: string="monit-once", code: untyped) =
var m = monit(name)
m.start()
code
m.finish()

template timeGo*(repeatTimes: int = repeatTimes, loopTimes: int = loopTimes,

template timeGo*(repeatTimes: int = repeatTimes,
loopTimes: int = loopTimes,
code: untyped) =
echo timeGo(code, repeatTimes, loopTimes)


when isMainModule:
timeOnce:
var a = 12
for i in 1 .. 10000:
a += i
echo a
timeOnce("Test With Name"):
var s = "Hello, Nim\n"
s &= "Let's change the world\n"
echo s

timeGo(1, 1):
var b = 12
Expand All @@ -179,6 +181,4 @@ when isMainModule:
for i in 1 .. 10000:
a += i



echo timeGo(foo())
2 changes: 1 addition & 1 deletion timeit.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.3.2"
version = "0.3.4"
author = "flywind"
description = "measuring execution times written in nim."
license = "MIT"
Expand Down

0 comments on commit cd73891

Please sign in to comment.