commit c1a0cde62da279d1bc6615c99c078f456fe20a08 Author: zara Date: Wed Apr 19 20:15:29 2023 +0800 创建小工具项目,添加精确计时功能,采用chrono库 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e41094f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.25) +project(utils) + +set(CMAKE_CXX_STANDARD 17) + +add_library(utils INTERFACE utils.h) diff --git a/cmake-build-debug/utils.h b/cmake-build-debug/utils.h new file mode 100644 index 0000000..2aa8d1b --- /dev/null +++ b/cmake-build-debug/utils.h @@ -0,0 +1,31 @@ +#ifndef __UTILS__ +#define __UTILS__ +#include +#include +namespace utils{ + + + class hdTimer{ + public: + hdTimer(){ + } + void tik(){ + start = std::chrono::high_resolution_clock::now(); + } + void tok(){ + end = std::chrono::high_resolution_clock::now(); + } + double cost(){ + return std::chrono::duration_cast(end-start).count(); + } + private: + + std::chrono::time_point start,end; + + }; + + +} + + +#endif \ No newline at end of file