example5_execution_time.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <chrono>

void exampleFunction() {
    for (int i = 0; i < 1000000; ++i);
}

int main() {
    auto start = std::chrono::high_resolution_clock::now();

    exampleFunction();

    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed = end - start;

    std::cout << "Execution time: " << elapsed.count() << " seconds\n";

    return 0;
}
Back to std_chrono