Performance testing utility.
Functions
|
Run performance tests for multiple candidate methods on collections of test data. |
|
Format performance counter output. |
|
Plot the results of a test run. |
|
Create a DataFrame from performance run output. |
Classes
|
Performance testing implementation for multiple candidates and data sets. |
Bases: object
Performance testing implementation for multiple candidates and data sets.
candidate_method – A single method, collection of method or a dict {label: function} of candidates.
test_data – A single datum or a dict {label: data} to evaluate candidates on.
sanity_check – If True, verify total expected runtime.
Warn of long runtimes above this limit (3 hours).
Run for all cases.
Note that the test case variant data isn’t included in the expected runtime computation, so increasing the amount of test data variants (at initialization) will reduce the amount of times each candidate is evaluated.
time_per_candidate – Desired runtime for each repetition per candidate label. Ignored if number is set.
repeat – Number of times to repeat for all candidates per data label.
number – Number of times to execute each test case, per repetition. Compute based on
per_case_time_allocation if None.
max_expected_runtime – Maximum expected runtime to allow before throwing an exception. Disabled if `None`. Default is one week (604 800 seconds).
Examples
If repeat=5 and time_per_candidate=3 for an instance with and 2 candidates, the total
runtime will be approximately 5 * 3 * 2 = 30 seconds.
A dict run_results on the form {candidate_label: {data_label: [runtime..]}}.
ValueError – If the total expected runtime exceeds max_expected_runtime.
Notes
Precomputed runtime is inaccurate for functions where a single call are longer than time_per_candidate.
By default, this function reports averages of all runs (repetition), as opposed to the built-in timeit which reports only the best result (in non-verbose mode).
See also
The timeit.Timer class which this implementation depends on.
Run performance tests for multiple candidate methods on collections of test data.
This is a convenience method which combines MultiCaseTimer.run(),
to_dataframe() and – if plotting is enabled – plot_run(). For full
functionally these methods should be use directly.
candidate_method – Candidate methods to evaluate.
test_data – Test data to evaluate.
time_per_candidate – Desired runtime for each repetition per candidate label.
plot – If True, plot a figure using plot_run().
**figure_kwargs – Keyword arguments for the barplot. Ignored if plot=False.
A long-format DataFrame of results.
ModuleNotFoundError – If Seaborn isn’t installed and plot=True.
Format performance counter output.
This function formats performance counter output based on the time elapsed. For t < 60 sec, accuracy is
increased whereas for durations above one minute a more user-friendly formatting is used.
start – Start time.
end – End time. Set to now if not given.
A formatted performance counter time.
Examples
>>> from rics.performance import format_perf_counter
>>> format_perf_counter(0, 3131) # 3131 seconds is about 52 minutes.
'0:52:11'
>>> format_perf_counter(0, 0.154)
'0.154 sec'
See also
Plot the results of a test run.
run_results – Output of rics.performance.MultiCaseTimer.run().
x – The value to plot on the X-axis. Default=derive.
unit – Time unit to plot on the Y-axis.
**figure_kwargs – Keyword arguments for the barplot.
ModuleNotFoundError – If Seaborn isn’t installed.
ValueError – For unknown unit arguments.