Пробовал следующие комбинации компилятора. Результаты во всех случаях одинаковы.
Код: Выделить всё
g++ -o perfTestGetDB -O2 -std=c++17 -DDO_COUNT_IN_FUNC perfTestGetDB.cpp
g++ -o perfTestGetDB -O2 -std=c++17 perfTestGetDB.cpp
Код: Выделить всё
#include
#include
#include
#include
const int numBits = 1536;
const int setSize = 500;
const int searchSize = 1000000;
void perfTestCountAndGet()
{
#ifdef DO_COUNT_IN_FUNC
boost::dynamic_bitset db1(numBits);
#endif
boost::dynamic_bitset db2(numBits);
int searchList[setSize];
// Use the current time as a seed for the random number generator
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 generator(seed); // Mersenne Twister 19937 generator
// Define the range of random numbers (0 to numBits - 1)
std::uniform_int_distribution distribution(0, numBits - 1);
for (int i = 0; i < setSize; i++) {
int idx = distribution(generator);
#ifdef DO_COUNT_IN_FUNC
db1.set(idx);
#endif
db2.set(idx);
}
// Define another random search index
for (int i = 0; i < setSize; i++) {
searchList[i] = distribution(generator);
}
#ifdef DO_COUNT_IN_FUNC
// Perform count
int count = db1.count();
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78382172/variability-in-computation-time-for-boostdynamic-bitsets-operator-with-dif[/url]
Мобильная версия