src/pylib/Lib/n_timeit

Source   Edit  

timeit

Types

NullaryFunc = concept self
    self()
Callable[, Any] Source   Edit  
TimeitParam = string | NullaryFunc
Source   Edit  
Timer = ref object
  
Source   Edit  

Vars

default_timer = default_timer_defval
Source   Edit  

Consts

default_number = 1000000
Source   Edit  
default_repeat = 5
Source   Edit  
NullStmt = "discard"
Source   Edit  

Procs

proc newTimer(stmt: TimeitParam = NullStmt; setup: TimeitParam = NullStmt;
              timer = default_timer; number = default_number): Timer
Source   Edit  

Templates

template autorange(self: Timer;
                   callable: proc (number: int; time_taken: float) = nil): (int,
    float)
Source   Edit  
template repeat(self: Timer; repeat = default_repeat; number = default_number): seq[
    float]
Source   Edit  
template repeat(stmt: TimeitParam = NullStmt; setup: TimeitParam = NullStmt;
                timer = default_timer; repeat = default_repeat;
                number = default_number): seq[float]
Source   Edit  
template timeit(repetitions: int; statements: untyped)

EXT. unstable.

returns nothing but send output to stdout.

output shows more information than Pythons.

Example:

var i = 0
timeit(10):
  i.inc
assert i == 10
Source   Edit  
template timeit(self: Timer; number = default_number): float
Source   Edit  
template timeit(stmt: TimeitParam = NullStmt; setup: TimeitParam = NullStmt;
                timer = default_timer; number = default_number): float

timeit(stmt, setup, number=1000000) with globals is globals()|locals()

stmt, setup are Callable or str literal

Example:

discard timeit("i.inc", "var i = 0")
assert i != 0

proc f() = discard
discard timeit(f)
proc retf(): int = 1
discard timeit(retf)
Source   Edit