Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Clojure
(time (f))
#include <chrono>

double measure() {
    using namespace std::chrono;
    const auto start{ high_resolution_clock::now() };
    f();
    const auto elapsed{ high_resolution_clock::now() - start };
    const double seconds{ duration_cast<duration<double>>(elapsed).count() };
    return seconds;
}

Be aware that high_resolution_clock may go back in time.

Caveat: the timing calls may be reordered. See https://stackoverflow.com/questions/37786547/enforcing-statement-order-in-c

New implementation...
< >
programming-idioms.org