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

operator()() method from fcf::NTest::SteadyClock class

unsigned long long operator()() const

Class: fcf::NTest::SteadyClock

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Returns the current time point in nanoseconds.

The operator() method is the primary way to retrieve the current time from a fcf::NTest::SteadyClock instance.

When called, it captures the current time point from the underlying std::chrono::steady_clock and converts it into a high-resolution unsigned long long value representing the total number of nanoseconds since the epoch. This method is monotonic, meaning it is guaranteed to never decrease, making it perfect for measuring elapsed time intervals.

Result
unsigned long long
- The current time point in nanoseconds.

Example: Manual High-Resolution Timestamping

Demonstrating how to use the operator() to capture two distinct time points and calculate the difference between them.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("ClockDemo", "Utility", "Timestamping") { // 1. Create an instance of the SteadyClock fcf::NTest::SteadyClock clock; // 2. Capture the first timestamp using the call operator unsigned long long time1 = clock(); // 3. Simulate some workload for (volatile int i = 0; i < 1000000; ++i) { ; } // 4. Capture the second timestamp unsigned long long time2 = clock(); // 5. Calculate the elapsed time unsigned long long diff = time2 - time1; // 6. Log the results fcf::NTest::log() << "Timestamping test completed." << std::endl; fcf::NTest::log() << " Time 1: " << time1 << " ns" << std::endl; fcf::NTest::log() << " Time 2: " << time2 << " ns" << std::endl; fcf::NTest::log() << " Diff: " << diff << " ns" << std::endl; // 7. Verify that time has actually passed FCF_TEST(diff > 0, "Elapsed time must be positive"); } 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: "ClockDemo" -> "Utility" -> "Timestamping" ... > Timestamping test completed. > Time 1: 36493003979747 ns > Time 2: 36493006343665 ns > Diff: 2363918 ns [SUCCESS] Test completed successfully (0.002`397`196 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.002`397`196 sec