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

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

void resume()

Class: fcf::NTest::Duration

Package: fcfTest

File: test.hpp

Available from version: 1.0.5

Resumes the time measurement after a pause, adjusting the global start time to exclude the paused duration.

The resume method is used to continue time measurement after a period of inactivity (pause - fcf::NTest::Duration::end()). It is a crucial part of the high-precision benchmarking process when you need to exclude setup or teardown time from the total execution duration.

Example: Benchmarking with pauses

Demonstrates how to use resume to exclude non-critical code execution time from the total benchmark results.

To run the application, use the command: app --test-log-level inf

#include <iostream> #include <vector> #include <algorithm> #include <thread> #include <chrono> // Define an implementation macro to include the implementation section in header files #define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DECLARE("Benchmark", "Pause", "ResumeDemo") { // Create a duration object for 1 iteration fcf::NTest::Duration bench(1); // 1. Start the measurement bench.begin(); // 2. Perform some critical work int sum = 0; for(int i = 0; i < 1000; ++i) sum += i; // 3. Pause the timer to perform non-critical operations (e.g., heavy I/O or sleeping) // We want to exclude this sleep time from our benchmark bench.end(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); // 4. Resume the timer // This will adjust the global start time to exclude the 100ms sleep bench.resume(); // 5. Perform more critical work for(int i = 0; i < 1000; ++i) sum += i; // 6. End the measurement bench.end(); // Output the results fcf::NTest::inf() << "Total duration (excluding pause): " << bench.totalDurationStr() << std::endl; fcf::NTest::inf() << "Last segment duration: " << bench.lastTotalDurationStr() << std::endl; FCF_TEST(sum > 0); } int main(int argc, char* argv[]) { bool error = false; fcf::NTest::cmdRun(argc, argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "Benchmark" -> "Pause" -> "ResumeDemo" ... Total duration (excluding pause): 0.000`009`316 Last segment duration: 0.000`006`442 Test completed (0.100`192`772 sec) All tests were completed. Number of tests: 1 Duration of execution of all tests: 0.100`192`772 sec