11#include " ../examples/GuardedVectorExample.h"
22
33#include < nanobench.h>
4+ #include < chrono>
45
56#include < vector>
67
8+ #if defined(__has_feature) // Clang
9+ # if __has_feature(thread_sanitizer)
10+ # define USING_THREAD_SANITIZER 1
11+ # endif
12+ #elif defined(__SANITIZE_THREAD__) // GCC
13+ # define USING_THREAD_SANITIZER 1
14+ #else
15+ # define USING_THREAD_SANITIZER 0
16+ #endif
717
818using namespace std ::chrono_literals;
919const auto minEpoch = 100ms;
@@ -35,7 +45,7 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
3545 }
3646 }
3747
38- #if defined(__has_feature) && __has_feature(thread_sanitizer)
48+ #if !USING_THREAD_SANITIZER
3949#ifndef NDEBUG // Only gives different perf in debug builds
4050 {
4151 ExampleGuardedVector<T> guardedvector;
@@ -73,7 +83,7 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
7383 });
7484 }
7585 }
76- #endif // defined(__has_feature) && __has_feature(thread_sanitizer)
86+ #endif // !USING_THREAD_SANITIZER
7787 if (withNoReserve)
7888 {
7989 {
@@ -94,7 +104,7 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
94104 }
95105 }
96106
97- #if defined(__has_feature) && __has_feature(thread_sanitizer)
107+ #if !USING_THREAD_SANITIZER
98108 {
99109 ExampleGuardedVector<T> guardedvector;
100110 for (size_t size : nbPushBacksPerIteration)
@@ -112,8 +122,8 @@ int BenchVector(ankerl::nanobench::Bench& bench, bool withNoReserve)
112122 });
113123 }
114124 }
125+ #endif // !USING_THREAD_SANITIZER
115126 }
116- #endif // defined(__has_feature) && __has_feature(thread_sanitizer)
117127 return x;
118128}
119129
0 commit comments