Class: fcf::NTest::Duration
Package: fcfTest
File: test.hpp
Available from version: 1.1.7
Returns a formatted string representation of the total duration of the last active execution segment.
The lastTotalDurationStr method provides a human-readable string representation of the total time elapsed during the most recent execution segment.
Unlike lastDurationStr, which returns the average time per iteration, this method returns the total time of the segment. The format depends on the a_friendly parameter.
The output format is determined by the a_friendly parameter:
- If a_friendly is true (default), the string follows the format:
SECONDS.MILLIS`MICROS`NANOS (e.g., 0.001`020`030).
- If a_friendly is false, the string follows a raw floating-point format with nanosecond precision (e.g.,
0.001020030).
Arguments
bool a_friendly = false
- If true, returns a human-friendly format (e.g., SECONDS.MILLIS`MICROS`NANOS). If false, returns a raw floating-point format with nanosecond precision.
Result
std::string
- A formatted string representing the total segment duration.
Example: Formatted total segment duration string
Demonstrating how to use lastTotalDurationStr to get the total time of the last segment in both friendly and raw formats.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DECLARE("Benchmark", "Format", "LastTotalDurationStrTest") {
fcf::NTest::Duration bench(1);
bench.begin();
for(volatile int i = 0; i < 1000000; ++i) { /* work */ }
bench.end();
// 1. Friendly format (default)
std::string friendly = bench.lastTotalDurationStr(true);
// 2. Raw format
std::string raw = bench.lastTotalDurationStr(false);
fcf::NTest::log() << "Friendly: " << friendly << std::endl;
fcf::NTest::log() << "Raw: " << raw << 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: "Benchmark" -> "Format" -> "LastTotalDurationStrTest" ...
> Friendly: 0.002`205`940
> Raw: 0.002205940
[SUCCESS] Test completed successfully (0.002`219`525 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.002`219`525 sec