c++ - Easily measure elapsed time for methods -


i want measure execution time of methods , found following topic:

easily measure elapsed time

there exists answer measuring function execution time with

#include <iostream> #include <chrono>  template<typename timet = std::chrono::milliseconds> struct measure {     template<typename f, typename ...args>     static typename timet::rep execution(f func, args&&... args)     {         auto start = std::chrono::system_clock::now();         func(std::forward<args>(args)...);         auto duration = std::chrono::duration_cast< timet>                              (std::chrono::system_clock::now() - start);         return duration.count();     } };  int main() {     std::cout << measure<>::execution(functor(dummy)) << std::endl; } 

is possible use code method measurement? how can change template types pass method , object like

measure<>::execution(object, method); 

or better

measure<>::execution(object.method(param)); 

by now, have following result:

struct measure {     template<class t, typename r>     static r execution(t& obj, r(t::*func)())     {         auto start = std::chrono::system_clock::now();         r result = (obj.*func)();         auto duration = std::chrono::duration_cast<std::chrono::microseconds>                             (std::chrono::system_clock::now() - start);         return result;     } }; 

but don't know how pass args , use shown in example above. have execute

measure::execution(obj, method); 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -