Skip to content

Instantly share code, notes, and snippets.

@DrPizza
Last active March 31, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrPizza/03acc53574ce4e0fc3df1c08cd528824 to your computer and use it in GitHub Desktop.
Save DrPizza/03acc53574ce4e0fc3df1c08cd528824 to your computer and use it in GitHub Desktop.
void store_buffers() {
static constexpr size_t items = 1ULL << 24;
static constexpr size_t mask = items - 1;
static constexpr size_t iterations = 1'000'000'000;
std::vector<std::vector<unsigned char> > arrays{ 12, std::vector<unsigned char>(items, '\0') };
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
__int32 unused[4];
unsigned __int32 also_unused;
{
__cpuidex(unused, 0, 0);
unsigned __int64 start = __rdtsc();
size_t i = iterations;
while(--i) {
size_t slot = i & mask;
unsigned char value = static_cast<unsigned char>(i & 0xff);
arrays[0][slot] = value;
arrays[1][slot] = value;
arrays[2][slot] = value;
arrays[3][slot] = value;
arrays[4][slot] = value;
arrays[5][slot] = value;
arrays[6][slot] = value;
arrays[7][slot] = value;
arrays[8][slot] = value;
arrays[9][slot] = value;
arrays[10][slot] = value;
arrays[11][slot] = value;
}
unsigned __int64 end = __rdtscp(&also_unused);
__cpuidex(unused, 0, 0);
std::cout << "combined: " << end - start << std::endl;
}
{
__cpuidex(unused, 0, 0);
unsigned __int64 start = __rdtsc();
size_t i = iterations;
while(--i) {
size_t slot = i & mask;
unsigned char value = static_cast<unsigned char>(i & 0xff);
arrays[0][slot] = value;
arrays[1][slot] = value;
arrays[2][slot] = value;
arrays[3][slot] = value;
arrays[4][slot] = value;
arrays[5][slot] = value;
}
i = iterations;
while(--i) {
size_t slot = i & mask;
unsigned char value = static_cast<unsigned char>(i & 0xff);
arrays[6][slot] = value;
arrays[7][slot] = value;
arrays[8][slot] = value;
arrays[9][slot] = value;
arrays[10][slot] = value;
arrays[11][slot] = value;
}
unsigned __int64 end = __rdtscp(&also_unused);
__cpuidex(unused, 0, 0);
std::cout << "split: " << end - start << std::endl;
}
::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_NORMAL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment