A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../error/error_code/../../../cpp/chrono/c/difftime.html below:

std::difftime - cppreference.com

Computes difference between two calendar times as std::time_t objects (time_end - time_beg) in seconds. If time_end refers to time point before time_beg then the result is negative.

[edit] Parameters time_beg, time_end - times to compare [edit] Return value

Difference between two times in seconds.

[edit] Notes

On POSIX systems, std::time_t is measured in seconds, and difftime is equivalent to arithmetic subtraction, but C and C++ allow fractional units for time_t.

[edit] Example
#include <ctime>
#include <iostream>
 
int main()
{
    std::time_t start = std::time(nullptr);
    volatile double d = 1.0;
 
    // some time-consuming operation
    for (int p = 0; p < 10000; ++p)
        for (int q = 0; q < 100000; ++q)
            d = d + p * d * q + d;
 
    std::cout << "Wall time passed: "
              << std::difftime(std::time(nullptr), start) << " s.\n";
}

Possible output:

[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4