lgy514

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 
#include <chrono>
#define TIMEDEBUG 
#ifdef TIMEDEBUG
#define  RD(X) {RunDuration o;o.begin();##X;o.end(#X);}
class RunDuration {
public:
    inline void begin() {
        _start = std::chrono::system_clock::now();
    }
    inline void end(const char * msg) {
        _end = std::chrono::system_clock::now();
        _duration = (_end - _start);
        std::cout << msg <<"\n" <<double(_duration.count()) << "s\n----------" << std::endl;
    }
private:
    std::chrono::system_clock::time_point _start;
    std::chrono::system_clock::time_point _end;
    std::chrono::duration<double> _duration;
};
#else
#define  RD(X)  X;
#endif

 

示例:

RD(printf("this is test \n"));

posted on 2020-07-16 16:36  lgy514  阅读(332)  评论(0编辑  收藏  举报