Skip to content

Commit

Permalink
use high_precision_clock in test_perf
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Feb 19, 2024
1 parent 36fa417 commit 7edcf73
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions scripts/test_perf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ EOF
#include <fstream>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <zserio/BitStreamReader.h>
#include <zserio/BitStreamWriter.h>
Expand All @@ -362,7 +363,6 @@ fi

cat >> "${BUILD_SRC_DIR}"/PerformanceTest.cpp << EOF
#if defined(_WIN32) || defined(_WIN64)
# include <windows.h>
#else
# include <time.h>
#endif
Expand All @@ -373,28 +373,14 @@ public:
static uint64_t getMicroTime()
{
#if defined(_WIN32) || defined(_WIN64)
FILETIME creation, exit, kernelTime, userTime;
GetThreadTimes(GetCurrentThread(), &creation, &exit, &kernelTime, &userTime);
return fileTimeToMicro(kernelTime) + fileTimeToMicro(userTime);
auto time = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(time.time_since_epoch()).count();
#else
struct timespec ts;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
return static_cast<uint64_t>(ts.tv_sec) * 1000000 + static_cast<uint64_t>(ts.tv_nsec) / 1000;
#endif
}
private:
#if defined(_WIN32) || defined(_WIN64)
static uint64_t fileTimeToMicro(const FILETIME& time)
{
uint64_t value = time.dwHighDateTime;
value <<= 8 * sizeof(time.dwHighDateTime);
value |= static_cast<uint64_t>(time.dwLowDateTime);
value /= 10;
return value;
}
#endif
};
EOF

Expand Down

0 comments on commit 7edcf73

Please sign in to comment.