MCPcopy Index your code
hub / github.com/ipython/ipython / TimeitResult

Class TimeitResult

IPython/core/magics/execution.py:73–134  ·  view source on GitHub ↗

Object returned by the timeit magic with info about the run. Contains the following attributes: loops: int number of loops done per measurement repeat: int number of times the measurement was repeated best: float best execution time / number all_runs :

Source from the content-addressed store, hash-verified

71
72
73class TimeitResult:
74 """
75 Object returned by the timeit magic with info about the run.
76
77 Contains the following attributes:
78
79 loops: int
80 number of loops done per measurement
81
82 repeat: int
83 number of times the measurement was repeated
84
85 best: float
86 best execution time / number
87
88 all_runs : list[float]
89 execution time of each run (in s)
90
91 compile_time: float
92 time of statement compilation (s)
93
94 """
95 def __init__(self, loops, repeat, best, worst, all_runs, compile_time, precision):
96 self.loops = loops
97 self.repeat = repeat
98 self.best = best
99 self.worst = worst
100 self.all_runs = all_runs
101 self.compile_time = compile_time
102 self._precision = precision
103 self.timings = [dt / self.loops for dt in all_runs]
104
105 @property
106 def average(self):
107 return math.fsum(self.timings) / len(self.timings)
108
109 @property
110 def stdev(self):
111 mean = self.average
112 return (math.fsum([(x - mean) ** 2 for x in self.timings]) / len(self.timings)) ** 0.5
113
114 def __str__(self):
115 pm = '+-'
116 if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
117 try:
118 "\xb1".encode(sys.stdout.encoding)
119 pm = "\xb1"
120 except:
121 pass
122 return "{mean} {pm} {std} per loop (mean {pm} std. dev. of {runs} run{run_plural}, {loops:,} loop{loop_plural} each)".format(
123 pm=pm,
124 runs=self.repeat,
125 loops=self.loops,
126 loop_plural="" if self.loops == 1 else "s",
127 run_plural="" if self.repeat == 1 else "s",
128 mean=_format_time(self.average, self._precision),
129 std=_format_time(self.stdev, self._precision),
130 )

Callers 1

timeitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…