Skip to content

Instantly share code, notes, and snippets.

@greenrobot
Created August 1, 2020 14:19
Show Gist options
  • Save greenrobot/b81a85491f370de2978fe2b6366ead6a to your computer and use it in GitHub Desktop.
Save greenrobot/b81a85491f370de2978fe2b6366ead6a to your computer and use it in GitHub Desktop.
Sorting 32 bit vs 64 bit integers: mini performance benchmark
TEST_CASE("IntSortSpeed-64vs32bit") {
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_int_distribution<uint32_t> int32Dist;
int count = 100000000;
std::vector<uint32_t> v32;
v32.reserve(count);
std::vector<uint64_t> v64;
v64.reserve(count);
StopWatch stopWatch;
for (int i = 0; i < count; ++i) {
uint32_t value = int32Dist(mt);
v32.push_back(value);
v64.push_back(value);
}
LOG_I("Created: %s", stopWatch.durationForLog().c_str());
stopWatch.reset();
std::sort(v32.begin(), v32.end());
LOG_I("32: %s", stopWatch.durationForLog().c_str());
stopWatch.reset();
std::sort(v64.begin(), v64.end());
LOG_I("64: %s", stopWatch.durationForLog().c_str());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment