Skip to content

Commit

Permalink
fix(py): add pysince for timeit.default_timer
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed Oct 15, 2024
1 parent 3ac6ae0 commit 44316ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/pylib/Lib/timeit.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import ../version
import ./sys
export list, noneType

export n_timeit except newTimer, repeat, print_exc, default_repeat
pysince(3,3):
const TimeItUseTime*{.booldefine: "timeit.usetime".} = true ## \
## disable this if don't wanna depending on `Lib/time`
when TimeItUseTime:
import ./time

export n_timeit except newTimer, repeat, print_exc, default_repeat, default_timer

when TimeItUseTime:
var default_timer* = pysince(3.3, time.perf_counter, n_timeit.default_timer)
else: export n_timeit.default_timer

template repeatImpl(xs: varargs[untyped]): untyped = n_timeit.repeat(xs) ##\
## to avoid `repeat`'s repeat param being replaced
Expand Down
2 changes: 1 addition & 1 deletion src/pylib/version.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func toVer(s: static float): MajorMinorVersion{.compileTime.} =
" debug: delta=" & $(minorF.int.float - minorF)
result.minor = int minorF

func pysince*[R](ver: static[float|MajorMinorVersion]; defExpr, elseExpr: R): R{.compileTime.} =
func pysince*[R](ver: static[float|MajorMinorVersion]; defExpr, elseExpr: R): R{.inline.} =
bind PyMajor, PyMinor, toVer
when (PyMajor, PyMinor) >= toVer(ver): defExpr
else: elseExpr

0 comments on commit 44316ec

Please sign in to comment.