Reputation: 37
I am trying to monitor the time a section of code takes to run in both nano seconds and milliseconds and i have the nanoseconds working and i am now trying to do a duration_cast to turn the nanoseconds into milliseconds but it isn't working it just outputs 0 and the code for the duration cast doesn't seem to run.
// Get start time
const auto startTime = std::chrono::high_resolution_clock::now();
// function here
// Get end time
const auto endTime = std::chrono::high_resolution_clock::now();
const auto durationNS = (endTime - startTime).count();
const auto int_ms = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
const auto durationMS = int_ms.count();
At the bottom you can see where i am doing my duration cast but it isn't working any advice?
Upvotes: 1
Views: 5699
Reputation: 37
const auto endTime = std::chrono::high_resolution_clock::now();
const auto durationNS = (endTime - startTime).count();
std::chrono::duration<double, std::milli> fp_ms = endTime - startTime;
const auto durationMS = fp_ms.count();
Above code works.
Upvotes: 1