ScoreTimer#
- class scio.utils.ScoreTimer(target)[source]#
Bases:
objectTimer for
Scoreinstances.Provides a context manager to easily time successive executions of
fit()and__call__()forScoreinstances. For correct usage, see__call__().Timing statistics are respectively stored in
calibrationandinferenceattributes.- Parameters:
target (
Scoreinstance) – The target instance, for which execution should be timed.
Note
Different statistics from the same
Scoreinstance may originate from different contexts (parameters, calibration data, boundrnet, …). If timing statistics need to be compared, it is up to the user to ensure full consistency since only the type of operation, the number of processed samples and the score’s parameters are stored alongside the execution time.Useful methods defined here
__call__(op, /, *, n_samples)Context manager to time execution and store results.
Useful attributes defined here
Timing statistics for calibrations.
Timing statistics for inferences.
Show statistics report in rich table.
Timing statistics for this instance, from oldest to newest.
The
Scoreinstance being timed.- __call__(op, /, *, n_samples)[source]#
Context manager to time execution and store results.
- Parameters:
op (
ScoreTimerOperationLike) – SeeScoreTimerOperation.n_samples (
int) – Number of samples to be processed duringop.
Example
with timer("calibration", n_calib): # Calibration procedure...
- Raises:
RuntimeError – If the instance’s
targetis already dead.
- calibration#
Timing statistics for calibrations.
- Returns:
calibration (
tuple[ScoreTimerStat, ...]) – SeeScoreTimerStat.
- inference#
Timing statistics for inferences.
- Returns:
inference (
tuple[ScoreTimerStat, ...]) – SeeScoreTimerStat.
- report#
Show statistics report in rich table.
Example
>>> # For a given `gram` instance already in use >>> gram.timer.report ScoreTimer report for Gram(separate_diagonal=False, cut_off=0.1, act_norm=2, calib_labels='pred', mode='raw') at 0x77346d30e490 ┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┓ ┃ Extra params ┃ Operation ┃ # samples ┃ Duration ┃ ┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━┩ │ max_gram_order=2 │ inference │ 20 │ 115.4 ms │ │ │ inference │ 1352 │ 6.585 s │ │ │ calibration │ 50 │ 302.9 ms │ ├──────────────────┼─────────────┼───────────┼──────────┤ │ max_gram_order=4 │ inference │ 20 │ 246.5 ms │ │ │ inference │ 1352 │ 13.78 s │ │ │ calibration │ 677 │ 6.819 s │ ╰──────────────────┴─────────────┴───────────┴──────────╯ Entries are listed from newest to oldest
Note
Shows nothing if there are no stats.
Warning
The behaviour is only guaranteed for classical (e.g. nonrecursive) parameter values.
- stats#
Timing statistics for this instance, from oldest to newest.
- Returns:
stats (
tuple[ScoreTimerStat, ...]) – SeeScoreTimerStat.