Skip to content

Commit 30c810c

Browse files
committed
fix: resolve Windows build errors and stack marker test failure
- replace auto with explicit std::size_t for benchmark range values - fix StackAllocator marker validation test logic (marker should differ after allocation) Signed-off-by: NotKeira <github.rxs06@accounts.keira.boo>
1 parent f13e6f9 commit 30c810c

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

benchmarks/bench_threadsafe_pool.cpp

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void BM_ThreadSafePoolAllocator_SingleThread(benchmark::State& state)
1818
pool.deallocate(ptr);
1919
}
2020

21-
state.SetItemsProcessed(state.iterations());
21+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations()));
2222
}
2323

2424
BENCHMARK(BM_ThreadSafePoolAllocator_SingleThread);
@@ -29,14 +29,14 @@ static void BM_ThreadSafePoolAllocator_MultiThread(benchmark::State& state)
2929
constexpr std::size_t block_count = 10000;
3030
ThreadSafePoolAllocator pool(block_size, block_count);
3131

32-
const int num_threads = state.range(0);
32+
const auto num_threads = static_cast<std::size_t>(state.range(0));
3333

3434
for (auto _ : state)
3535
{
3636
std::vector<std::thread> threads;
3737
threads.reserve(num_threads);
3838

39-
for (int i = 0; i < num_threads; ++i)
39+
for (std::size_t i = 0; i < num_threads; ++i)
4040
{
4141
threads.emplace_back([&pool]()
4242
{
@@ -52,32 +52,37 @@ static void BM_ThreadSafePoolAllocator_MultiThread(benchmark::State& state)
5252
}
5353
}
5454

55-
state.SetItemsProcessed(state.iterations() * num_threads);
55+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations() * num_threads));
5656
}
5757

58-
BENCHMARK(BM_ThreadSafePoolAllocator_MultiThread)->Arg(2)->Arg(4)->Arg(8)->UseRealTime();
58+
BENCHMARK(BM_ThreadSafePoolAllocator_MultiThread)
59+
->Arg(2)
60+
->Arg(4)
61+
->Arg(8)
62+
->UseRealTime();
5963

6064
static void BM_ThreadSafePoolAllocator_Contention(benchmark::State& state)
6165
{
6266
constexpr std::size_t block_size = 64;
6367
constexpr std::size_t block_count = 1000;
6468
ThreadSafePoolAllocator pool(block_size, block_count);
6569

66-
const int num_threads = state.range(0);
70+
const auto num_threads = static_cast<std::size_t>(state.range(0));
6771

6872
for (auto _ : state)
6973
{
7074
std::vector<std::thread> threads;
7175
threads.reserve(num_threads);
7276

73-
for (int i = 0; i < num_threads; ++i)
77+
for (std::size_t i = 0; i < num_threads; ++i)
7478
{
7579
threads.emplace_back([&pool]()
7680
{
7781
constexpr int operations = 100;
7882
for (int j = 0; j < operations; ++j)
7983
{
80-
if (void* ptr = pool.allocate()) pool.deallocate(ptr);
84+
void* ptr = pool.allocate();
85+
if (ptr) pool.deallocate(ptr);
8186
}
8287
});
8388
}
@@ -88,21 +93,25 @@ static void BM_ThreadSafePoolAllocator_Contention(benchmark::State& state)
8893
}
8994
}
9095

91-
state.SetItemsProcessed(state.iterations() * num_threads * 100);
96+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations() * num_threads * 100));
9297
}
9398

94-
BENCHMARK(BM_ThreadSafePoolAllocator_Contention)->Arg(2)->Arg(4)->Arg(8)->UseRealTime();
99+
BENCHMARK(BM_ThreadSafePoolAllocator_Contention)
100+
->Arg(2)
101+
->Arg(4)
102+
->Arg(8)
103+
->UseRealTime();
95104

96105
static void BM_NewDelete_MultiThread(benchmark::State& state)
97106
{
98-
const int num_threads = state.range(0);
107+
const auto num_threads = static_cast<std::size_t>(state.range(0));
99108

100109
for (auto _ : state)
101110
{
102111
std::vector<std::thread> threads;
103112
threads.reserve(num_threads);
104113

105-
for (int i = 0; i < num_threads; ++i)
114+
for (std::size_t i = 0; i < num_threads; ++i)
106115
{
107116
threads.emplace_back([]()
108117
{
@@ -119,26 +128,30 @@ static void BM_NewDelete_MultiThread(benchmark::State& state)
119128
}
120129
}
121130

122-
state.SetItemsProcessed(state.iterations() * num_threads);
131+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations() * num_threads));
123132
}
124133

125-
BENCHMARK(BM_NewDelete_MultiThread)->Arg(2)->Arg(4)->Arg(8)->UseRealTime();
134+
BENCHMARK(BM_NewDelete_MultiThread)
135+
->Arg(2)
136+
->Arg(4)
137+
->Arg(8)
138+
->UseRealTime();
126139

127140
static void BM_ThreadSafePoolAllocator_BulkOperations(benchmark::State& state)
128141
{
129142
constexpr std::size_t block_size = 64;
130143
constexpr std::size_t block_count = 10000;
131144
ThreadSafePoolAllocator pool(block_size, block_count);
132145

133-
const std::size_t operations_per_thread = state.range(0);
134-
constexpr int num_threads = 4;
146+
const auto operations_per_thread = static_cast<std::size_t>(state.range(0));
147+
constexpr std::size_t num_threads = 4;
135148

136149
for (auto _ : state)
137150
{
138151
std::vector<std::thread> threads;
139152
threads.reserve(num_threads);
140153

141-
for (int i = 0; i < num_threads; ++i)
154+
for (std::size_t i = 0; i < num_threads; ++i)
142155
{
143156
threads.emplace_back([&pool, operations_per_thread]()
144157
{
@@ -164,7 +177,11 @@ static void BM_ThreadSafePoolAllocator_BulkOperations(benchmark::State& state)
164177
}
165178
}
166179

167-
state.SetItemsProcessed(state.iterations() * num_threads * operations_per_thread);
180+
state.SetItemsProcessed(static_cast<int64_t>(state.iterations() * num_threads * operations_per_thread));
168181
}
169182

170-
BENCHMARK(BM_ThreadSafePoolAllocator_BulkOperations)->Arg(100)->Arg(500)->Arg(1000)->UseRealTime();
183+
BENCHMARK(BM_ThreadSafePoolAllocator_BulkOperations)
184+
->Arg(100)
185+
->Arg(500)
186+
->Arg(1000)
187+
->UseRealTime();

tests/test_stack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ TEST_CASE("StackAllocator marker validation", "[stack]")
158158
REQUIRE(marker != nullptr);
159159
REQUIRE(ptr2 != nullptr);
160160

161-
REQUIRE(marker == stack.get_marker());
161+
REQUIRE(marker != stack.get_marker());
162162
}
163163

164164
TEST_CASE("StackAllocator zero-size allocation", "[stack]")

0 commit comments

Comments
 (0)