uint8_t MASKS[] =
{
0b10000000, // 0
0b01000000, // 1
0b00100000, // 2
0b00010000, // 3
0b00001000, // 4
0b00000100, // 5
0b00000010, // 6
0b00000001, // 7
};
uint8_t MASK = 0b10000000;
int BYTE_COUNT = 60000000;
int ROUND_COUNT = 10;
uint8_t* bytes = new uint8_t [BYTE_COUNT];
uint8_t bit = -1;
double timeAccumulator = 0;
for (int k = 0; k < ROUND_COUNT; ++k)
{
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
for (int i = 0; i < BYTE_COUNT; ++i)
{
uint8_t currentByte = bytes[i];
for (int j = 0; j < 8; ++j)
{
// bit = currentByte & MASKS[j]; // Elapsed time = 708.4 milliseconds. Bit value: ☺ (+- 6 millis)
bit = (currentByte << j) & MASK; // Elapsed time = 763.5 milliseconds. Bit value: А (+- 6 millis)
}
}
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
double timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
timeAccumulator += timeMillis;
}
std::cout
<< "Elapsed time = "
<< timeAccumulator / ROUND_COUNT
<< " milliseconds. Bit value: "
<< bit
<< std::endl;
bit = currentByte & MASKS[j]; // Elapsed time = 2362 milliseconds.
bit = (currentByte << j) & MASK; // Elapsed time = 2574 milliseconds.
void* mem = allocator.allocate(sizeof(Body));
Body* b = new (mem) Body();
allocator.free(b, sizeof(Body));