rust
use times::*;
This crate will be typically added in Cargo.toml
under [dev-dependecies]
and then used by source files under tests
or benches
directories. It can be used whenever the runtime speed comparisons are of interest, which is practically always.
Times
is suitable for testing algorithms that work on a whole Vec
of data, for example sort. Or even whole matrices of data &[Vec<T>]
. The correctness of the results
should be tested separately. Here the results are thrown away and only the execution time in nanoseconds is recorded.
Random data are automatically generated using ran
crate and then algorithms from a given array of closures are repeatedly run and their statistics are collected (median of the execution times and the measurements error). The repeated runs reduce the temporary effects of changing machine loads. The effects of outliers are minimised by using mad (median of absolute differences from median, which is the most stable measure of data spread). All the algorithms are run over the same data for exact comparisons but the data is changed for each repeat run.
The error estimates the doubt about the reliability of repeated measurements. High value means poor reliability. Relative accuracy can often be increased by increasing the number of repeats. The extraneous influence of the machine load is also reduced as the length of the data vectors increases.
We generate new random data for each repeated run. The differences in errors between the algorithms inform us about their relative stability under changing data. Some algorithms suffer from data sensitivity (poor worst-case performance) and this may be indicated by relatively high errors, e.g. for mutsort
(the standard Rust sort).
The tests are also automatically repeated over different lengths of the input data vectors, in specified range and step. This enables comparisons of algorithms as the difficulty of the problem increases. The algorithms with lower computational complexity and/or faster implementations will start to win more convincingly at greater lengths. When the given range is too big, then the process may have to be externally terminated. Depending, of course, on the algorithms and the speed of the machine. It is recommended to use modest values at first.
Mad, more stable standard error.
Ease of Use - just specify:
Sorted output.
The algorithms are automatically sorted by their execution times within each length of data category, i.e. the fastest algorithm in each data category will be listed first and the slowest last.
Four different and-types of data are fully supported: u8,u16,u64,f64
. Other end-types may be added later. See tests/tests.rs
.
Simple function bench
for timing closures that take no or constant arguments.
Bench functions for testing algorithms on input slices, e.g. on input data type &[f64]
:
benchu8, benchu16, benchu64 and benchf64
.
Bench functions for testing algorithms that mutate their input, e.g. data type: &mut [f64]
.
A mutable version has to be used whenever any one of the tested algorithms mutates its input:
mutbenchu8, mutbenchu16, mutbenchu64 and mutbenchf64
.
Bench functions for algorithms taking nd data (matrices), e.g. &[Vecbenchvvu8, benchvvu16, benchvvu64 and benchvvf64
.
Please see tests/test.rs
for examples of how to specify the closures and call these functions on them.
Version 1.0.9 Added mutbenchu16
and benchvvu16
. Simplified the printouts.
Version 1.0.8 Added benchu16
. Updated dependencies medians
to ^2.1 and indxvec
to ^1.4.
Version 1.0.7 Updated dependency medians
to v.2.0.0 and indxvec
.
Version 1.0.6 Updated dependency medians
and github actions.
Version 1.0.5 Updated dependency ran
to v.1.0
.
Version 1.0.4 Instead of magnitudes number, now takes the actual range and step of the data lengths. Is more flexible.
Version 1.0.3 Updated the dependencies.
Version 1.0.2 Added simple bench
for timing closures that take no or constant arguments.
Version 1.0.1 Redefined standard error as MAD as a percentage of Median (more stable measure). All listed times are now medians rather than means. Also, as there are now no sums of squares of nanoseconds, the danger of overflow on very slow tests is reduced.
Version 1.0.0 Promoted to v 1.0.0 following period of non problematic use.