On this page
  1. timeit.Timer
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

timeit.Timer

Prev: timeit.timeit | Up: timeit
Rel: timeit.default_timer, timeit.repeat, timeit.timeit
Ref: docs.python.org — timeit.Timer
Tags: #public #python3 #stdlib #timeit


Import

import timeit
from timeit import Timer

Signature & Overview

timeit.Timer(stmt='pass', setup='pass', timer=<built-in function perf_counter>, globals=None)

Class for timing execution speed of small code snippets.

Methods & Attributes

Usage

import timeit

t = timeit.Timer('sum(xs)', globals={'xs': list(range(100))})
elapsed = t.timeit(number=1000)
assert elapsed >= 0.0

Gotchas

REPL Inspect

from timeit import Timer
help(Timer)

Linked from

Related notes