FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

lastDurationStr() method from fcf::NTest::Duration class

std::string lastDurationStr(bool a_friendly = false)

Class: fcf::NTest::Duration

Package: fcfTest

File: test.hpp

Available from version: 1.1.7

Returns a formatted string representation of the average duration of a single iteration within the last active execution segment.

The lastDurationStr method provides a human-readable string representation of the average time taken by one iteration during the most recent execution segment.

It internally calls lastDuration and formats the resulting nanoseconds into a readable format. 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 average duration.

Example: Formatted average duration string

Demonstrating the difference between friendly and raw string formats for the average iteration duration.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DECLARE("Benchmark", "Format", "LastDurationStrTest") { fcf::NTest::Duration bench(1000); bench.begin(); for(volatile int i = 0; i < bench.iterationCount(); ++i) { /* work */ } bench.end(); // 1. Friendly format (default) std::string friendly = bench.lastDurationStr(true); // 2. Raw format std::string raw = bench.lastDurationStr(false); fcf::NTest::log() << "Avg Friendly: " << friendly << std::endl; fcf::NTest::log() << "Avg 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" -> "LastDurationStrTest" ... > Avg Friendly: 0.000`000`005 > Avg Raw: 0.000000005 [SUCCESS] Test completed successfully (0.000`037`136 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`037`136 sec