ulfben icon

C++: Q&D function timer

ulfben | PRO | 11/26/17 09:54:01 PM UTC | 0 ⭐ | 1222 👁️ | Never ⏰ | []
C++ |

600 B

|

None

|

0 👍

/

0 👎

template<typename Time = std::chrono::microseconds,
    typename Clock = std::chrono::high_resolution_clock>
    struct QuickTimer{
    template<typename F, typename... Args>
    static Time duration(F&& f, Args... args){
        auto start = Clock::now();
        std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
        auto end = Clock::now();
        return std::chrono::duration_cast<Time>(end - start);
    }
};
 
//Usage:
using namespace std::chrono;
auto t = QuickTimer<>::duration(myFunction);
std::cout << duration<double, std::milli>(t).count() << "ms\n";
std::cout << duration<double, std::nano>(t).count() << "ns\n";

Comments

  • Gyqizv icon
    04/02/26 06:16:24 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  • Yuizcko icon
    05/18/26 01:15:03 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best Pastebin.com alternatives paste sites list
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400