memgraph/tests/concurrent/dynamic_bitset.cpp
Kruno Tomola Fabro 9bd845a62e Added max_no_threads.
It is meant for easily change no threads in concurrent tests.
2016-09-13 18:08:34 +01:00

40 lines
1.2 KiB
C++

#include "common.h"
constexpr size_t THREADS_NO = std::min(max_no_threads, 8);
constexpr size_t op_per_thread = 1e5;
constexpr size_t bit_part_len = 2;
constexpr size_t no_slots = 1e4;
constexpr size_t key_range = no_slots * THREADS_NO * bit_part_len;
constexpr size_t no_sets_per_clear = 2;
int main()
{
DynamicBitset<> db;
auto seted =
collect_set(run<std::vector<bool>>(THREADS_NO, [&](auto index) {
auto rand = rand_gen(no_slots);
auto clear_op = rand_gen_bool(no_sets_per_clear);
std::vector<bool> set(key_range);
for (size_t i = 0; i < op_per_thread; i++) {
size_t num =
rand() * THREADS_NO * bit_part_len + index * bit_part_len;
if (clear_op()) {
db.clear(num, bit_part_len);
for (int j = 0; j < bit_part_len; j++) {
set[num + j] = false;
}
} else {
db.set(num, bit_part_len);
for (int j = 0; j < bit_part_len; j++)
set[num + j] = true;
}
}
return set;
}));
check_set(db, seted);
}