asv_runner.util#

Various low-level utilities.

Module Contents#

Functions#

ceildiv

Calculate the ceiling division of two numbers.

human_float

Formats a float into a human-friendly string.

human_time

Formats a duration in seconds into a human-friendly time string.

Data#

API#

asv_runner.util.terminal_width#

None

asv_runner.util.ceildiv(numerator, denominator)#

Calculate the ceiling division of two numbers.

Parameters

numerator (int)

The numerator in the division.

denominator (int)

The denominator in the division.

Returns

int: The result of the division rounded up to the nearest integer.

Notes

This function calculates the ceiling division of two numbers, i.e., division that rounds up. It is equivalent to math.ceil(numerator/denominator), but avoids the conversion of numerator and denominator to float.

asv_runner.util.human_float(value, significant=3, truncate_small=None, significant_zeros=False)#

Formats a float into a human-friendly string.

Parameters

value (float)

The float value to format.

significant (int)

Number of significant digits to include in the output. Default is 3.

truncate_small (int, optional)

If defined, leading zeros of numbers < 1 are counted as significant.

significant_zeros (bool)

If True, trailing unnecessary zeros are included. Default is False.

Returns

str: A string representing the float with human-friendly significant digits.

Notes

Switches to scientific notation for very large or very small numbers. The magnitude of the number is calculated using math.log10(value).

asv_runner.util._human_time_units#

((‘ns’, 1e-09), (‘μs’, 1e-06), (‘ms’, 0.001), (‘s’, 1), (‘m’, 60), (‘h’,), (‘d’,), (‘w’,), (‘y’,), (…

asv_runner.util.human_time(seconds, err=None)#

Formats a duration in seconds into a human-friendly time string.

Depending on the number of seconds given, can be one of::

1w 3d
2d 4h
1h 5m
1m 4s
  15s

The representation is always exactly 6 characters long.

Parameters

seconds (int)

The number of seconds to represent.

err (float, optional)

If provided, formats the duration as “{value}±{err}”, e.g., “1h±5m”. It can be used to represent the uncertainty in the measurement.

Returns

str: A human-friendly representation of the given duration. If the duration is NaN, returns “n/a”.