Skip to content

Instantly share code, notes, and snippets.

@Langerz82
Created July 18, 2018 03:16
Show Gist options
  • Save Langerz82/e46204b0212a2e8ab63d74095d04aacf to your computer and use it in GitHub Desktop.
Save Langerz82/e46204b0212a2e8ab63d74095d04aacf to your computer and use it in GitHub Desktop.
uint32 testChars;
const uint32 numTests = 1024;
ByteBuffer buff[numTests];
ByteBuffer buffOld[numTests];
ByteBufferNew buffNew[numTests];
for (int n = 0; n < 20; ++n)
{
for (int m = 0; m < numTests; ++m)
{
testChars = (rand() % 500) + 1;
buffOld[m].reserve(500);
buffNew[m].reserve(500);
for (uint32 i = 0; i < testChars; ++i)
{
char c = (rand() % 26) + 65;
buff[m] << c;
}
}
auto start = std::chrono::steady_clock::now();
for (int m = 0; m < numTests; ++m)
{
for (uint32 i = 0; i < buff[m].size()-4;)
{
buffOld[m] << (int)buff[m][i+=4]; // made int as uint8 is native and is unfair test.
}
}
float oldTime = (float)std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - start).count();
start = std::chrono::steady_clock::now();
for (int m = 0; m < numTests; ++m)
{
for (uint32 i = 0; i < buff[m].size()-4;)
{
buffNew[m] << (int)buff[m][i += 4]; // made int as uint8 is native and is unfair test.
}
}
float newTime = (float)std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - start).count();
char buffer[10];
sprintf(buffer, "%.3f%%", (100 - (newTime / oldTime) * 100));
std::cout << "BuffNew improvement: " << buffer << std::endl;
}
char c;
std::cin >> c;
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment