#include#include using namespace std::chrono; int main() { auto start = high_resolution_clock::now(); for (int i = 0; i < 1000000; i++) { // Loop code } auto end = high_resolution_clock::now(); auto duration = duration_cast (end - start).count(); std::cout << "Time taken by function: " << duration << " microseconds" << std::endl; return 0; }
#includeIn this example, the Timer elapsed function measures the time it takes for the `someFunction()` function to complete and outputs the duration in microseconds. The package library used is also `chrono`.#include using namespace std::chrono; void someFunction() { // Function code } int main() { auto start = high_resolution_clock::now(); someFunction(); auto end = high_resolution_clock::now(); auto duration = duration_cast (end - start).count(); std::cout << "Time taken by function: " << duration << " microseconds" << std::endl; return 0; }