mahmoud
15
Q:

measure time taken by code in c++

#include <chrono> 

auto start = chrono::high_resolution_clock::now(); 

// CODE

auto stop = chrono::high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << duration.count() << endl; 
5
#include <chrono> 
using namespace std::chrono; 
  
// Use auto keyword to avoid typing long 
// type definitions to get the timepoint 
// at this instant use function now() 
auto start = high_resolution_clock::now(); 

  
// After function call 
auto stop = high_resolution_clock::now(); 
auto duration = duration_cast<microseconds>(stop - start); 
  
// To get the value of duration use the count() 
// member function on the duration object 
cout << duration.count() << endl; 
0

New to Communities?

Join the community