mirror of
https://github.com/gunchev/bench.git
synced 2025-11-20 12:15:48 +00:00
Add loop_lowercase_toupper
This commit is contained in:
parent
0379190649
commit
b6930e02c5
4 changed files with 15 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,5 +1,6 @@
|
||||||
# Project specific
|
# Project specific
|
||||||
/build/
|
/build/
|
||||||
|
/CMakeLists.txt.user
|
||||||
|
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@
|
||||||
Various C++ benchmarks:
|
Various C++ benchmarks:
|
||||||
|
|
||||||
- transform.cpp - benchmark std::transform vs loop and custom lowercase and tolower
|
- transform.cpp - benchmark std::transform vs loop and custom lowercase and tolower
|
||||||
|

|
||||||
|
|
|
||||||
BIN
bench_lowercase.png
Normal file
BIN
bench_lowercase.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
|
|
@ -53,3 +53,16 @@ int main(int argc, char** argv) {
|
||||||
benchmark::RunSpecifiedBenchmarks();
|
benchmark::RunSpecifiedBenchmarks();
|
||||||
return EX_OK;
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue