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

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Project specific
/build/
/CMakeLists.txt.user
# Prerequisites
*.d

View file

@ -4,3 +4,4 @@
Various C++ benchmarks:
- transform.cpp - benchmark std::transform vs loop and custom lowercase and tolower
![](bench_lowercase.png)

BIN
bench_lowercase.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

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