Skip to content

Commit 60bb0b8

Browse files
committed
drop custom windows-specific clock
Windows C++ standard libraries have had good support for high_resolution clock for a while now. We can drop our workaround clock.
1 parent c5c162c commit 60bb0b8

1 file changed

Lines changed: 3 additions & 44 deletions

File tree

include/picobench/picobench.hpp

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
// VERSION HISTORY
3232
//
3333
// 2.9.0 (2026-04-30) * Completely drop binding benchmarks to a single core
34+
// * Drop custom Windows clock and just use
35+
// std::high_resolution_clock everywhere
3436
// 2.8.0 (2025-12-15) Switch to SemVer to appease certain package managers
3537
//
3638
// 2.08 (2025-04-04) Internal. This file was not affected
@@ -157,7 +159,7 @@
157159
namespace PICOBENCH_NAMESPACE
158160
{
159161

160-
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(PICOBENCH_TEST)
162+
#if defined(PICOBENCH_TEST)
161163
struct high_res_clock
162164
{
163165
typedef long long rep;
@@ -376,11 +378,6 @@ class global_registry
376378
#include <cstdlib>
377379
#include <algorithm>
378380

379-
#if defined(_WIN32)
380-
# define WIN32_LEAN_AND_MEAN
381-
# include <Windows.h>
382-
#endif
383-
384381
namespace PICOBENCH_NAMESPACE
385382
{
386383

@@ -956,28 +953,6 @@ class runner : public registry
956953
b->_istate = b->_states.begin();
957954
}
958955

959-
#if !defined(PICOBENCH_DONT_BIND_TO_ONE_CORE)
960-
// set thread affinity to first cpu
961-
// so the high resolution clock doesn't miss cycles
962-
{
963-
#if defined(_WIN32)
964-
SetThreadAffinityMask(GetCurrentThread(), 1);
965-
#elif defined(__APPLE__)
966-
thread_affinity_policy_data_t policy = {0};
967-
thread_policy_set(
968-
pthread_mach_thread_np(pthread_self()),
969-
THREAD_AFFINITY_POLICY,
970-
(thread_policy_t)&policy, 1);
971-
#else
972-
cpu_set_t cpuset;
973-
CPU_ZERO(&cpuset);
974-
CPU_SET(0, &cpuset);
975-
976-
sched_setaffinity(0, sizeof(cpu_set_t), &cpuset);
977-
#endif
978-
}
979-
#endif
980-
981956
// we run a random benchmark from it incrementing _istate for each
982957
// when _istate reaches _states.end(), we erase the benchmark
983958
// when the vector becomes empty, we're done
@@ -1490,22 +1465,6 @@ int global_registry::set_bench_suite(const char* name)
14901465
return 0;
14911466
}
14921467

1493-
#if (defined(_MSC_VER) || defined(__MINGW32__)) && !defined(PICOBENCH_TEST)
1494-
1495-
static const long long high_res_clock_freq = []() -> long long
1496-
{
1497-
LARGE_INTEGER frequency;
1498-
QueryPerformanceFrequency(&frequency);
1499-
return frequency.QuadPart;
1500-
}();
1501-
1502-
high_res_clock::time_point high_res_clock::now()
1503-
{
1504-
LARGE_INTEGER t;
1505-
QueryPerformanceCounter(&t);
1506-
return time_point(duration((t.QuadPart * rep(period::den)) / high_res_clock_freq));
1507-
}
1508-
#endif
15091468
}
15101469

15111470
#endif

0 commit comments

Comments
 (0)