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

fcf::NTest::TimeDuration() method from fcf::NTest::TimeDuration class

void fcf::NTest::TimeDuration(unsigned long long a_duration = 0)

Class: fcf::NTest::TimeDuration

Package: fcfTest

File: test.hpp ( link_to_the_implementation_in_the_file )

Available from version: 1.2.5

A class representing a duration of time, stored in nanoseconds.

The fcf::NTest::TimeDuration class is a lightweight wrapper around an unsigned long long value, representing time intervals in nanoseconds. It provides a rich set of arithmetic operators and conversion methods to facilitate precise time measurements and comparisons within the fcf::NTest framework.

Arguments

unsigned long long a_duration = 0
- The duration value in nanoseconds.

Example: Basic usage of TimeDuration

Demonstrating how to create a duration, perform arithmetic, and format it for output.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("TimeDemo", "Basics", "ConstructorAndArithmetic") { // 1. Create a duration of 1.5 seconds (1,500,000,000 nanoseconds) fcf::NTest::TimeDuration duration(1500000000ULL); // 2. Perform arithmetic operations fcf::NTest::TimeDuration added = duration + 500000000ULL; // Add 0.5s fcf::NTest::TimeDuration subtracted = duration - 1000000000ULL; // Subtract 1s // 3. Verify results using FCF_TEST FCF_TEST(added.count() == 2000000000ULL, added.count()); FCF_TEST(subtracted.count() == 500000000ULL, subtracted.count()); // 4. Print formatted output std::cout << "Original: " << duration.str(true) << std::endl; std::cout << "Added: " << added.str(true) << std::endl; std::cout << "Subtracted: " << subtracted.str(true) << 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: "TimeDemo" -> "Basics" -> "ConstructorAndArithmetic" ... Original: 1.500`000`000 Added: 2.000`000`000 Subtracted: 0.500`000`000 [SUCCESS] Test completed successfully (0.000`000`000 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`000`000 sec