Answers for "how to calculate time of execution in c++"

C++
4

c++ measure time of function

//***C++11 Style:***
#include <chrono>

std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();

std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << "[µs]" << std::endl;
std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::nanoseconds> (end - begin).count() << "[ns]" << std::endl;
Posted by: Guest on June-29-2020
0

c++ execution time

int main() 
{
  time_t start, end;
  time(&start); // start time
  // {your code goes here}
  time(&end);  // end time 
  double time_taken = double(end - start); // calulate diffrence
  std::cout << " duration: " << time_taken << " s \n"; 
}
Posted by: Guest on January-17-2022

Code answers related to "how to calculate time of execution in c++"

Browse Popular Code Answers by Language