Browse Source

创建小工具项目,添加精确计时功能,采用chrono库

master
zara 2 years ago
commit
c1a0cde62d
  1. 6
      CMakeLists.txt
  2. 31
      cmake-build-debug/utils.h

6
CMakeLists.txt

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.25)
project(utils)
set(CMAKE_CXX_STANDARD 17)
add_library(utils INTERFACE utils.h)

31
cmake-build-debug/utils.h

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
#ifndef __UTILS__
#define __UTILS__
#include <iostream>
#include <chrono>
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<std::chrono::nanoseconds>(end-start).count();
}
private:
std::chrono::time_point<std::chrono::steady_clock> start,end;
};
}
#endif
Loading…
Cancel
Save