Files
nvbench/testing
Oleksandr Pavlyk d483a5bc73 Harden quartile statistics and measurement timeout handling (#392)
* Replace forwarding with semantically more accurate std::move

Also add comment within percentile_rank to document precondition
on input values checked with assert statement.

Also, sharpened the comment around percentile_rank function

* Duplicate-heavy boundary test is added

Prepare duplicate heavy input and check sort-based
quartile computation result with selection-based one.

std::nth_element only guarantees that the nth element
is the value that would appear there in sorted order;
it does not fully sort equal partitions. Bugs in the
selection implementation, especially when selecting Q1
from the left half and Q3 from the right half after
selecting the median, are more likely to show up when
many samples equal the quartile values.

* Generate cold summaries only if some accepted samples have been accumulated

Cold measurement can discard throttled trials before incrementing the accepted
sample count, then stop on timeout with zero recorded samples. In that case,
only emit the sample-size summary and skip derived timing, bandwidth, clock, and
bulk summaries that require accepted samples.

This avoids divide-by-zero mean calculations and quartile/IQR computation over
empty sample vectors.

Keep timeout diagnostics reachable for zero-sample runs and add an explicit
warning when no accepted cold samples were recorded. Factor timeout warning
emission into a private helper so the zero-sample and normal paths share the
same diagnostic logic.

Suppress low-sample relative stdev noise

Add a statistics helper that returns no relative standard-deviation noise until
there are enough samples for a meaningful estimate. Use it for cold CPU/GPU and
CPU-only summaries so the low-sample +inf stdev sentinel is not published as
real relative noise or used for max-noise timeout warnings.

Add statistics coverage for suppressing the low-sample sentinel and computing
relative stdev noise once the sample threshold is reached.

compute_standard_deviation_noise return nullopt if standard deviation is not finite

Test verify that noise is nullopt when not enough samples are accumulated

Added statistics::has_enough_samples_for_noise_estimate(...)

Used it in standard_deviation, compute_standard_deviation_noise,
compute_robust_noise.

Added timeout diagnostics in cold and CPU-only paths.
if max-noise is configured and the run timed out before enough
samples exist to estimate noise, the log now says that explicitly,
otherwise the existing “over noise threshold” warning remains
unchanged.

Added a statistics test assertion for the new sample-count
predicate.

* Test quartile values across selection threshold

Add fixed expected-value assertions for quartile tests around the
sort/selection switch point, including duplicate-heavy inputs. This keeps the
tests from only proving that both implementations agree with each other.

* Add NaN guards to percentiles and quartiles computation routines

* Add tests for handling of NaNs in quartile routine inputs

* Add comment re magic sort/select threshold value

* Refactor logic of emitting warnings between cold and cpu-only measures

Introduce new header file with inline implementation. Use it
from measure_cold.cuh and measure_cpu_only.cxx

* Add static assertion that ValueType is a floating-point type

* Check consistency of sort- vs. select-based quartiles using threshold constant

Expose quartile threshold value, use it in testing to test around that value.

* Collapsed two branches with identical bodies

* test_compute_standard_deviation_noise exercises other invalid inputs

* Preserve stdev noise summaries for low sample counts

Keep legacy stdev/relative summary tags present even when too few
samples are available to compute a meaningful standard-deviation noise
estimate. Use the standard-deviation unavailable sentinel for those
values so existing summary consumers continue to see the expected tags.

Factor the sentinel into the statistics helpers and use it from both
standard_deviation() and stdev_noise_or_sentinel(), keeping the schema
compatibility behavior explicit and tested.

* timeout_warnings now treats engaged NaN and negative stdev noise as unavailable

Add a focused test target, nvbench.test.measure_timeout_warnings, covering:

  - NaN stdev noise -> “unable to estimate noise”
  - negative stdev noise -> “unable to estimate noise”
  - +inf stdev noise -> “over noise threshold”

* Test nullopt explicitly in warning check test

check_noise_warning() now takes std::optional<nvbench::float64_t>,
matching the production helper, and the test now covers
std::nullopt explicitly in addition to NaN, negative, and +inf.

* Tighten statistics and timeout warning tests

Document that percentile helpers return quiet NaNs for NaN-containing inputs.

Make quartile expected-value tests compute ranks from the documented
round(p / 100 * (n - 1)) rule instead of reusing statistics::percentile_rank(),
so rank regressions are caught independently.

Extend timeout-warning coverage to exercise the too-few-samples max-noise path
in addition to unavailable, invalid, and infinite stdev-noise inputs.

* Test for timeout warnings for min-samples and min-time
2026-07-02 07:23:18 -05:00
..
2026-05-19 15:10:58 -05:00
2026-05-19 15:10:58 -05:00
2026-05-15 15:14:30 -05:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00
2025-04-14 17:26:12 +00:00