Created
December 20, 2013 10:47
-
-
Save gradha/8053167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit d6df5ee13b8c090b3e51b73f0083c77047ffef25 | |
| Author: Grzegorz Adam Hankiewicz <gradha@imap.cc> | |
| Date: Thu Dec 19 11:54:46 2013 +0100 | |
| Attempt to make elapsed statement macro returning a value | |
| diff --git a/lib/pure/times.nim b/lib/pure/times.nim | |
| index 6483a42..1e31207 100644 | |
| --- a/lib/pure/times.nim | |
| +++ b/lib/pure/times.nim | |
| @@ -717,6 +717,23 @@ proc format*(info: TTimeInfo, f: string): string = | |
| {.pop.} | |
| +template measureElapsed(timingProc: expr, body: stmt): expr {.immediate.} = | |
| + var result = timingProc() | |
| + try: | |
| + body | |
| + finally: | |
| + let t2 = timingProc() | |
| + result = t2 - result | |
| + | |
| +#template measureElapsed(timingProc, v: expr, body: stmt): stmt {.immediate.} = | |
| +# block: | |
| +# let t1: type(v) = timingProc() | |
| +# try: | |
| +# body | |
| +# finally: | |
| +# let t2: type(v) = timingProc() | |
| +# v = (t2 - t1) | |
| + | |
| when isMainModule: | |
| # $ date --date='@2147483647' | |
| # Tue 19 Jan 03:14:07 GMT 2038 | |
| @@ -747,3 +764,14 @@ when isMainModule: | |
| # Interval tests | |
| assert((t4 - initInterval(years = 2)).format("yyyy") == "1995") | |
| assert((t4 - initInterval(years = 7, minutes = 34, seconds = 24)).format("yyyy mm ss") == "1990 24 10") | |
| + | |
| + let ttt = measureElapsed(epochTime): | |
| + echo "Hey there" | |
| + #var cpuDiff, timeDiff: float | |
| + | |
| + #measureElapsed(cpuTime, cpuDiff): | |
| + # echo "Hey there" | |
| + #echo repr(cpuDiff) | |
| + #measureElapsed(epochTime, timeDiff): | |
| + # echo "Hey there" | |
| + #echo repr(timeDiff) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment