Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
start=start)
start += nvalue
if self.test_calibrate_warmups(nwarmup, unit):
break
if len(self.warmups) >= MAX_WARMUP_VALUES:
print("ERROR: failed to calibrate the number of warmups")
values = [format_value(unit, value)
for loops, value in self.warmups]
print("Values (%s): %s" % (len(values), ', '.join(values)))
sys.exit(1)
nwarmup += 1
if self.args.verbose:
print("Calibration: use %s warmups" % format_number(nwarmup))
print()
if self.args.recalibrate_warmups:
self.metadata['recalibrate_warmups'] = nwarmup
else:
self.metadata['calibrate_warmups'] = nwarmup
if args.verbose:
text = format_value(unit, value)
if is_warmup:
text = ('%s (loops: %s, raw: %s)'
% (text,
format_number(self.loops),
format_value(unit, raw_value)))
print("%s %s: %s" % (value_name, start + index, text))
if calibrate_loops and raw_value < args.min_time:
if self.loops * 2 > MAX_LOOPS:
print("ERROR: failed to calibrate the number of loops")
print("Raw timing %s with %s is still smaller than "
"the minimum time of %s"
% (format_value(unit, raw_value),
format_number(self.loops, 'loop'),
format_timedelta(args.min_time)))
sys.exit(1)
self.loops *= 2
# need more values for the calibration
nvalue += 1
index += 1
def format_run(bench, run_index, run, common_metadata=None, raw=False,
verbose=0, lines=None):
if lines is None:
lines = []
inner_loops = run.get_inner_loops()
if run._is_calibration():
if run._is_calibration_warmups():
warmups = run._get_calibration_warmups()
action = 'calibrate the number of warmups: %s' % format_number(warmups)
elif run._is_recalibration_warmups():
warmups = run._get_calibration_warmups()
action = 'recalibrate the number of warmups: %s' % format_number(warmups)
elif run._is_recalibration_loops():
loops = run._get_calibration_loops()
action = 'recalibrate the number of loops: %s' % format_number(loops)
else:
loops = run._get_calibration_loops()
action = 'calibrate the number of loops: %s' % format_number(loops)
lines.append("Run %s: %s" % (run_index, action))
if raw:
name = 'raw calibrate'
else:
name = 'calibrate'
unit = bench.get_unit()
format_value = bench.format_value
start, end = dates
lines.append("Start date: %s" % format_datetime(start, microsecond=False))
lines.append("End date: %s" % format_datetime(end, microsecond=False))
# Raw value minimize/maximum
raw_values = bench._get_raw_values()
lines.append("Raw value minimum: %s" % bench.format_value(min(raw_values)))
lines.append("Raw value maximum: %s" % bench.format_value(max(raw_values)))
lines.append('')
# Number of values
ncalibration_runs = sum(run._is_calibration() for run in bench._runs)
lines.append("Number of calibration run: %s"
% format_number(ncalibration_runs))
lines.append("Number of run with values: %s"
% (format_number(nrun - ncalibration_runs)))
lines.append("Total number of run: %s" % format_number(nrun))
lines.append('')
# Number of values
nwarmup = bench._get_nwarmup()
text = format_number(nwarmup)
if isinstance(nwarmup, float):
text += ' (average)'
lines.append('Number of warmup per run: %s' % text)
nvalue_per_run = bench._get_nvalue_per_run()
text = format_number(nvalue_per_run)
if isinstance(nvalue_per_run, float):
text += ' (average)'
lines.append('Number of value per run: %s' % text)
lines.append("Number of calibration run: %s"
% format_number(ncalibration_runs))
lines.append("Number of run with values: %s"
% (format_number(nrun - ncalibration_runs)))
lines.append("Total number of run: %s" % format_number(nrun))
lines.append('')
# Number of values
nwarmup = bench._get_nwarmup()
text = format_number(nwarmup)
if isinstance(nwarmup, float):
text += ' (average)'
lines.append('Number of warmup per run: %s' % text)
nvalue_per_run = bench._get_nvalue_per_run()
text = format_number(nvalue_per_run)
if isinstance(nvalue_per_run, float):
text += ' (average)'
lines.append('Number of value per run: %s' % text)
# Loop iterations per value
loops = bench.get_loops()
inner_loops = bench.get_inner_loops()
total_loops = loops * inner_loops
if isinstance(total_loops, int):
text = format_number(total_loops)
else:
text = "%s (average)" % total_loops
if not(isinstance(inner_loops, int) and inner_loops == 1):
if isinstance(loops, int):
loops = format_number(loops, 'outer-loop')
if raw:
warmups = [bench.format_value(value * (loops * inner_loops))
for loops, value in run.warmups]
values = [value * total_loops for value in values]
else:
warmups = run.warmups
if warmups:
warmups = [value for loops, value in warmups]
warmups = _format_values_diff(bench, warmups, raw, total_loops)
values = _format_values_diff(bench, values, raw, total_loops)
if verbose >= 0:
loops = run.get_loops()
lines.append("Run %s: %s, %s, %s"
% (run_index,
format_number(len(warmups), 'warmup'),
format_number(len(values), 'value'),
format_number(loops, 'loop')))
else:
lines.append("Run %s:" % run_index)
if warmups and show_warmup:
if raw:
name = 'raw warmup'
else:
name = 'warmup'
for index, warmup in enumerate(warmups, 1):
lines.append('- %s %s: %s' % (name, index, warmup))
if raw:
name = 'raw value'
else:
lines.append("Start date: %s" % format_datetime(start, microsecond=False))
lines.append("End date: %s" % format_datetime(end, microsecond=False))
# Raw value minimize/maximum
raw_values = bench._get_raw_values()
lines.append("Raw value minimum: %s" % bench.format_value(min(raw_values)))
lines.append("Raw value maximum: %s" % bench.format_value(max(raw_values)))
lines.append('')
# Number of values
ncalibration_runs = sum(run._is_calibration() for run in bench._runs)
lines.append("Number of calibration run: %s"
% format_number(ncalibration_runs))
lines.append("Number of run with values: %s"
% (format_number(nrun - ncalibration_runs)))
lines.append("Total number of run: %s" % format_number(nrun))
lines.append('')
# Number of values
nwarmup = bench._get_nwarmup()
text = format_number(nwarmup)
if isinstance(nwarmup, float):
text += ' (average)'
lines.append('Number of warmup per run: %s' % text)
nvalue_per_run = bench._get_nvalue_per_run()
text = format_number(nvalue_per_run)
if isinstance(nvalue_per_run, float):
text += ' (average)'
lines.append('Number of value per run: %s' % text)
# Loop iterations per value
for loops, value in run.warmups]
values = [value * total_loops for value in values]
else:
warmups = run.warmups
if warmups:
warmups = [value for loops, value in warmups]
warmups = _format_values_diff(bench, warmups, raw, total_loops)
values = _format_values_diff(bench, values, raw, total_loops)
if verbose >= 0:
loops = run.get_loops()
lines.append("Run %s: %s, %s, %s"
% (run_index,
format_number(len(warmups), 'warmup'),
format_number(len(values), 'value'),
format_number(loops, 'loop')))
else:
lines.append("Run %s:" % run_index)
if warmups and show_warmup:
if raw:
name = 'raw warmup'
else:
name = 'warmup'
for index, warmup in enumerate(warmups, 1):
lines.append('- %s %s: %s' % (name, index, warmup))
if raw:
name = 'raw value'
else:
name = 'value'
for index, value in enumerate(values, 1):
if isinstance(nvalue_per_run, float):
text += ' (average)'
lines.append('Number of value per run: %s' % text)
# Loop iterations per value
loops = bench.get_loops()
inner_loops = bench.get_inner_loops()
total_loops = loops * inner_loops
if isinstance(total_loops, int):
text = format_number(total_loops)
else:
text = "%s (average)" % total_loops
if not(isinstance(inner_loops, int) and inner_loops == 1):
if isinstance(loops, int):
loops = format_number(loops, 'outer-loop')
else:
loops = '%.1f outer-loops (average)'
if isinstance(inner_loops, int):
inner_loops = format_number(inner_loops, 'inner-loop')
else:
inner_loops = "%.1f inner-loops (average)" % inner_loops
text = '%s (%s x %s)' % (text, loops, inner_loops)
lines.append("Loop iterations per value: %s" % text)
lines.append("Total number of values: %s" % format_number(nvalue))
lines.append('')
# Minimum
table = []