timerit.relative module

Helpers for making relative statements about an increase or decrase

class timerit.relative.Relative[source]

Bases: object

static percent_change(new, old)[source]

new is old changed by percent

Parameters:
  • new (Number) – the value before a change

  • old (Number) – the value after a change

Return type:

float

Notes

negative numbers are percent increases positive numbers are percent decreases

Example

>>> Relative.percent_change(5, 1)
-400.0
>>> Relative.percent_change(1, 5)
80.0
static percent_decrease(new, old)[source]

new is percent`% smaller than `old

Parameters:
  • new (Number) – the value before a change

  • old (Number) – the value after a change

Return type:

float

>>> Relative.percent_decrease(1, 5)
80.0
>>> Relative.percent_decrease(2153, 3469)
37.9360...
static percent_increase(new, old)[source]

new is percent`% larger than `old

Parameters:
  • new (Number) – the value before a change

  • old (Number) – the value after a change

Return type:

float

Example

>>> Relative.percent_increase(5, 1)
400.0
>>> Relative.percent_increase(8.6, 8.5)
1.176...
static percent_smaller(new, old)[source]

new is percent`% smaller than `old

Parameters:
  • new (Number) – the value before a change

  • old (Number) – the value after a change

Returns:

a percent decrease

Return type:

float

static percent_bigger(new, old)[source]

new is percent`% smaller than `old

Parameters:
  • new (Number) – the value before a change

  • old (Number) – the value after a change

Returns:

a percent increase

Return type:

float

static percent_slower(new, old)[source]

new is X percent slower than old

Parameters:
  • new (float) – measure of duration before a change

  • old (float) – measure of duration after a change (with same units as new)

Returns:

a percent increase in duration

Return type:

float

Example

>>> from timerit.relative import Relative
>>> old = 8.72848
>>> new = 9.59755
>>> print('{:.3f}% slower'.format(Relative.percent_slower(new, old)))
9.957% slower
>>> new = 3.6053
>>> old = 1.3477
>>> Relative.percent_slower(new, old)
>>> print('{:.3f}% slower'.format(Relative.percent_slower(new, old)))
167.515% slower
static percent_faster(new, old)[source]

new is percent`% faster than `old

Parameters:
  • new (float) – measure of duration before a change

  • old (float) – measure of duration after a change (with same units as new)

Returns:

a percent decrease in duration

Return type:

float

References

Notes

Equivalent to Relative.percent_decrease, because Faster means time is decreasing.

Example

>>> new = 8.59755
>>> old = 8.72848
>>> print('{:.3f}% faster'.format(Relative.percent_faster(new, old)))
1.500% faster
>>> new = 0.6053
>>> old = 1.3477
>>> Relative.percent_faster(new, old)
>>> print('{:.3f}% faster'.format(Relative.percent_faster(new, old)))
55.086% faster