criterion.rs icon indicating copy to clipboard operation
criterion.rs copied to clipboard

Consider accepting a value less than 10 in `Criterion::sample_size`

Open terror opened this issue 3 years ago • 4 comments

Currently working on a project where we need to benchmark a function that performs a very expensive initialization step upfront and then proceeds to process data. Since the function requires a slow initialization step and performs repetitive data processing, we would get the information we need by running the function a single time as opposed to running it the current minimum number of times (10).

Would it be possible to allow passing in a smaller sample size, in our case 1? In our case, we don't need statistical analysis, because our benchmark is a measure of bytes process per second so we can just divide total bytes processed by runtime to get an accurate indication of performance.

terror avatar Feb 13 '22 18:02 terror

If you don't need any statistical analysis then you don't need criterion and are probably better off timing the function yourselves. You can do this in a benchmark program that exists in parallel with your ordinary criterion benchmarks.

lemmih avatar Feb 13 '22 18:02 lemmih

Would this be a big change to support in criterion? It would be nice to have all our benchmarks be criterion benchmarks, for consistency, and since there are other useful features of criterion that we would need to replicate, in particular tracking whether benchmarks are getting better or worse over time.

casey avatar Feb 13 '22 19:02 casey

The analysis machinery doesn't work with only a single data point. You can get around that by duplicating that data point but that's kinda hacky. I'll still review PRs related to this, though. If you can find a robust implementation then I'll gladly accept it.

lemmih avatar Feb 13 '22 19:02 lemmih

Hi! I have the same problem and I wanted to ask a question from ignorance: do the statistical analyses break if you run, for example, 3 samples? Maybe you could lower the threshold without damaging the internal structure, the computationally time-consuming cases would still be a problem, but this time they would be a small one

Genarito avatar Feb 22 '22 13:02 Genarito