Commit 114ffdb0 authored by Benjamin Summerton's avatar Benjamin Summerton

Added `bench` template back in

parent c2870865
...@@ -32,7 +32,6 @@ There exist more functions than what is described here. Read the documentation ...@@ -32,7 +32,6 @@ There exist more functions than what is described here. Read the documentation
in `stopwatch.nim` to find out. Some samples are at the end of this document. in `stopwatch.nim` to find out. Some samples are at the end of this document.
Breaking Changes Breaking Changes
---------------- ----------------
Here is what has changed names: Here is what has changed names:
...@@ -43,10 +42,6 @@ Here is what has changed names: ...@@ -43,10 +42,6 @@ Here is what has changed names:
All of the fields in `Stopwatch` have been marked invisible. All of the fields in `Stopwatch` have been marked invisible.
The `bench` template has also been removed for the time being. If there are
some requests to add it back in, I'll do so.
Examples Examples
-------- --------
......
...@@ -61,6 +61,21 @@ proc totalSecs*(sw: var Stopwatch): float {.inline.} ...@@ -61,6 +61,21 @@ proc totalSecs*(sw: var Stopwatch): float {.inline.}
#===============#
#== Templates ==#
#===============#
## A simple template that will wrap the `start()` and `stop()` calls around
## a block of code. Make sure that the passed in Stopwatch has been
## initialized. If the Stopwatch is already running, it will stop it it first.
template bench*(sw: Stopwatch; body: untyped): untyped =
sw.stop()
sw.start()
body
sw.stop()
#===============================# #===============================#
#== Time Conversion Functions ==# #== Time Conversion Functions ==#
#===============================# #===============================#
......
[Package] [Package]
name = "stopwatch" name = "stopwatch"
version = "1.1" version = "1.2"
author = "define-private-public" author = "define-private-public"
description = "A fork of \"stopwatch\" that adds more features" description = "A simple timing object for benchmarking code and other things."
license = "MIT" license = "MIT"
[Deps] [Deps]
......
...@@ -76,3 +76,6 @@ echo "total(u)=", sw.totalUsecs ...@@ -76,3 +76,6 @@ echo "total(u)=", sw.totalUsecs
echo "total(n)=", sw.totalNsecs echo "total(n)=", sw.totalNsecs
echo "" echo ""
bench(sw, sleep(1000))
echo "bench(sleep(1000))=", 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