just paste it into Compiler Explorer, clang 6.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void fancierRotate2(unsigned int *arr, const bool *control, int count, int rot0, int rot1) | |
| { | |
| for (int i = 0; i < count; ++i) | |
| { | |
| int rot = control[i] ? rot1 : rot0; | |
| arr[i] = (arr[i] << (rot & 31)) | (arr[i] >> (-rot & 31)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
void fancierRotate2(unsigned int *arr, const bool *control, int count, int rot0, int rot1)
{
for (int i = 0; i < count; ++i)
{
int rot = control[i] ? rot1 : rot0;
arr[i] = (arr[i] << (rot & 31)) | (arr[i] >> (-rot & 31));
}
}
static void fanRotate(benchmark::State& state)
{
// Code before the loop is not measured
std::string x = "hello";
unsigned int count = 20;
unsigned int* arr = new unsigned int[count];
bool* control = new bool[count];
int rot0 = 11;
int rot1 = 22;
for (auto _ : state)
{
fancierRotate2(arr, control, count, rot0, rot1);
}
}
BENCHMARK(fanRotate);
^ Google bench code