fcf::NTest::TimeDuration
median(
int a_level
= 0)
const
Class: fcf::NTest::DurationBasic
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
Available from version: 1.2.5
Returns the median duration for a specific level using the internal histogram.
The median method provides the median value of the duration distribution. Unlike the average, the median is more robust against outliers in the measurement data.
This method relies on the internal fcf::NTest::HistogramBasic to estimate the median value.
Arguments
int a_level = 0
- The index of the measurement level.
Result
fcf::NTest::TimeDuration
- The median duration recorded for the specified level.
Example: Calculating Median Duration
Demonstrating how to get the median time per iteration.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <thread>
#include <chrono>
FCF_TEST_DEFINE("Bench", "Stats", "MedianTest") {
fcf::NTest::Duration bench(1000);
bench([](){
std::this_thread::sleep_for(std::chrono::milliseconds(1));
});
fcf::NTest::TimeDuration med = bench.median(0);
fcf::NTest::log() << "Median duration: " << med.str(true) << std::endl;
fcf::NTest::log() << bench.histogram(0).toBarChart() << std::endl;
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "Bench" -> "Stats" -> "MedianTest" ...
> Median duration: 0.001`065`381
> |
> || |
> || |
> || |
> ||||
> ||||
> |||||
> |||||
> |||||
> |||||||||
> ══════════
> OX (value): [0.001`026`521 : 0.001`182`526]; Step: 15600.50
> OY (count): [2 : 260]; Step: 25.80
>
[SUCCESS] Test completed successfully (1.091`778`701 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 1.091`778`701 sec