Add loop_lowercase_toupper

This commit is contained in:
Doncho N. Gunchev 2023-02-05 03:50:19 +02:00
parent 0379190649
commit b6930e02c5
Signed by: dgunchev
GPG key ID: D30FD19F37E002A9
4 changed files with 15 additions and 0 deletions

View file

@ -53,3 +53,16 @@ int main(int argc, char** argv) {
benchmark::RunSpecifiedBenchmarks();
return EX_OK;
}
static void loop_lowercase_toupper(benchmark::State& state) {
for (auto _ : state) { // Code inside this loop is measured repeatedly
std::string name = data;
for (char& c : name) {
if (c >= 'a' && c <= 'z') {
c = static_cast<char>(std::toupper(c));
}
}
benchmark::DoNotOptimize(name); // Make sure the variable is not optimized away by compiler
}
}
BENCHMARK(loop_lowercase_toupper); // Register the function as a benchmark