diff --git a/test/RngTest/inc/Timer.h b/test/RngTest/inc/Timer.h new file mode 100644 index 0000000..a2851ba --- /dev/null +++ b/test/RngTest/inc/Timer.h @@ -0,0 +1,59 @@ +#ifndef VECCORE_TIMER_H +#define VECCORE_TIMER_H + +#include + +using namespace std::chrono; + +template +class Timer { + using clock = high_resolution_clock; + +public: + Timer() : fStart(), fStop() { Start(); } + + void Reset() { Start(); } + + void Start() { fStart = clock::now(); } + + double Elapsed() + { + fStop = clock::now(); + return duration_cast(fStop - fStart).count(); + } + +private: + high_resolution_clock::time_point fStart, fStop; +}; + +#if !defined(VECCORE_CUDA_DEVICE_COMPILATION) + +class cycles { +}; + +template <> +class Timer { +public: + Timer() { Start(); } + + void Reset() { Start(); } + + void Start() { fStart = GetCycleCount(); } + + double Elapsed() { return static_cast(GetCycleCount() - fStart); } + +private: + unsigned long long int fStart; + + inline __attribute__((always_inline)) unsigned long long int GetCycleCount() + { + unsigned int hi, lo; + asm volatile("cpuid\n\t" + "rdtsc" + : "=a"(lo), "=d"(hi)); + return ((unsigned long long)lo) | (((unsigned long long)hi) << 32); + } +}; +#endif + +#endif diff --git a/test/RngTest/src/PdfBenchmarker.cc b/test/RngTest/src/PdfBenchmarker.cc index 265cb1c..9396069 100644 --- a/test/RngTest/src/PdfBenchmarker.cc +++ b/test/RngTest/src/PdfBenchmarker.cc @@ -1,7 +1,7 @@ #include "PdfBenchmarker.h" #include "PdfBenchmarker_cpu.h" -#include "VecCore/Timer.h" +#include "Timer.h" namespace vecrng { diff --git a/test/RngTest/src/PdfBenchmarker_cpu.cc b/test/RngTest/src/PdfBenchmarker_cpu.cc index 0c2ac64..5b76fd9 100644 --- a/test/RngTest/src/PdfBenchmarker_cpu.cc +++ b/test/RngTest/src/PdfBenchmarker_cpu.cc @@ -1,4 +1,4 @@ -#include "VecCore/Timer.h" +#include "Timer.h" #include "VecMath/Rng/MRG32k3a.h" diff --git a/test/RngTest/src/RngBenchmarker.cc b/test/RngTest/src/RngBenchmarker.cc index 562f04b..49a794d 100644 --- a/test/RngTest/src/RngBenchmarker.cc +++ b/test/RngTest/src/RngBenchmarker.cc @@ -1,7 +1,7 @@ #include "RngBenchmarker.h" #include "RngBenchmarker_cpu.h" -#include "VecCore/Timer.h" +#include "Timer.h" namespace vecrng { diff --git a/test/RngTest/src/RngBenchmarker_cpu.cc b/test/RngTest/src/RngBenchmarker_cpu.cc index 780d2ff..9885245 100644 --- a/test/RngTest/src/RngBenchmarker_cpu.cc +++ b/test/RngTest/src/RngBenchmarker_cpu.cc @@ -1,4 +1,4 @@ -#include "VecCore/Timer.h" +#include "Timer.h" #include "VecMath/Rng/MRG32k3a.h" #include "VecMath/Rng/Philox.h"