Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::difftime

      From cppreference.com
      <cpp‎ |chrono‎ |c
       
       
      Date and time library
       
       
      Defined in header<ctime>
      double difftime(std::time_t time_end,std::time_t time_beg);

      Computes difference between two calendar times asstd::time_t objects (time_end- time_beg) in seconds. Iftime_end refers to time point beforetime_beg then the result is negative.

      Contents

      [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, anddifftime is equivalent to arithmetic subtraction, but C and C++ allow fractional units fortime_t.

      [edit]Example

      Run this code
      #include <ctime>#include <iostream> int main(){std::time_t start=std::time(nullptr);volatiledouble d=1.0; // some time-consuming operationfor(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:

      Wall time passed: 9 s.

      [edit]See also

      (C++11)
      a time interval
      (class template)[edit]
      C documentation fordifftime
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/c/difftime&oldid=161514"

      [8]ページ先頭

      ©2009-2025 Movatter.jp