diff options
-rw-r--r-- | benchmarks/inttypes_benchmark.cpp | 15 | ||||
-rw-r--r-- | benchmarks/stdlib_benchmark.cpp | 48 | ||||
-rw-r--r-- | benchmarks/unistd_benchmark.cpp | 36 | ||||
-rw-r--r-- | benchmarks/util.h | 7 | ||||
-rw-r--r-- | benchmarks/wctype_benchmark.cpp | 60 |
5 files changed, 28 insertions, 138 deletions
diff --git a/benchmarks/inttypes_benchmark.cpp b/benchmarks/inttypes_benchmark.cpp index f123eb8e9..b96384e9e 100644 --- a/benchmarks/inttypes_benchmark.cpp +++ b/benchmarks/inttypes_benchmark.cpp @@ -19,16 +19,5 @@ #include <benchmark/benchmark.h> #include "util.h" -void BM_inttypes_strtoimax(benchmark::State& state) { - while (state.KeepRunning()) { - strtoimax(" -123", nullptr, 0); - } -} -BIONIC_BENCHMARK(BM_inttypes_strtoimax); - -void BM_inttypes_strtoumax(benchmark::State& state) { - while (state.KeepRunning()) { - strtoumax(" -123", nullptr, 0); - } -} -BIONIC_BENCHMARK(BM_inttypes_strtoumax); +BIONIC_TRIVIAL_BENCHMARK(BM_inttypes_strtoimax, strtoimax(" -123", nullptr, 0)); +BIONIC_TRIVIAL_BENCHMARK(BM_inttypes_strtoumax, strtoumax(" -123", nullptr, 0)); diff --git a/benchmarks/stdlib_benchmark.cpp b/benchmarks/stdlib_benchmark.cpp index 6afe7aa57..ec3f6f248 100644 --- a/benchmarks/stdlib_benchmark.cpp +++ b/benchmarks/stdlib_benchmark.cpp @@ -216,45 +216,9 @@ static void BM_stdlib_mbrtowc(benchmark::State& state) { } BIONIC_BENCHMARK_WITH_ARG(BM_stdlib_mbrtowc, "0"); -void BM_stdlib_atoi(benchmark::State& state) { - for (auto _ : state) { - benchmark::DoNotOptimize(atoi(" -123")); - } -} -BIONIC_BENCHMARK(BM_stdlib_atoi); - -void BM_stdlib_atol(benchmark::State& state) { - for (auto _ : state) { - benchmark::DoNotOptimize(atol(" -123")); - } -} -BIONIC_BENCHMARK(BM_stdlib_atol); - -void BM_stdlib_strtol(benchmark::State& state) { - for (auto _ : state) { - benchmark::DoNotOptimize(strtol(" -123", nullptr, 0)); - } -} -BIONIC_BENCHMARK(BM_stdlib_strtol); - -void BM_stdlib_strtoll(benchmark::State& state) { - for (auto _ : state) { - benchmark::DoNotOptimize(strtoll(" -123", nullptr, 0)); - } -} -BIONIC_BENCHMARK(BM_stdlib_strtoll); - -void BM_stdlib_strtoul(benchmark::State& state) { - for (auto _ : state) { - benchmark::DoNotOptimize(strtoul(" -123", nullptr, 0)); - } -} -BIONIC_BENCHMARK(BM_stdlib_strtoul); - -void BM_stdlib_strtoull(benchmark::State& state) { - for (auto _ : state) { - benchmark::DoNotOptimize(strtoull(" -123", nullptr, 0)); - } -} -BIONIC_BENCHMARK(BM_stdlib_strtoull); - +BIONIC_TRIVIAL_BENCHMARK(BM_stdlib_atoi, atoi(" -123")); +BIONIC_TRIVIAL_BENCHMARK(BM_stdlib_atol, atol(" -123")); +BIONIC_TRIVIAL_BENCHMARK(BM_stdlib_strtol, strtol(" -123", nullptr, 0)); +BIONIC_TRIVIAL_BENCHMARK(BM_stdlib_strtoll, strtoll(" -123", nullptr, 0)); +BIONIC_TRIVIAL_BENCHMARK(BM_stdlib_strtoul, strtoul(" -123", nullptr, 0)); +BIONIC_TRIVIAL_BENCHMARK(BM_stdlib_strtoull, strtoull(" -123", nullptr, 0)); diff --git a/benchmarks/unistd_benchmark.cpp b/benchmarks/unistd_benchmark.cpp index 98e885843..d697dfd52 100644 --- a/benchmarks/unistd_benchmark.cpp +++ b/benchmarks/unistd_benchmark.cpp @@ -20,37 +20,11 @@ #include <benchmark/benchmark.h> #include "util.h" -static void BM_unistd_getpid(benchmark::State& state) { - while (state.KeepRunning()) { - getpid(); - } -} -BIONIC_BENCHMARK(BM_unistd_getpid); - -static void BM_unistd_getpid_syscall(benchmark::State& state) { - while (state.KeepRunning()) { - syscall(__NR_getpid); - } -} -BIONIC_BENCHMARK(BM_unistd_getpid_syscall); +BIONIC_TRIVIAL_BENCHMARK(BM_unistd_getpid, getpid()); +BIONIC_TRIVIAL_BENCHMARK(BM_unistd_getpid_syscall, syscall(__NR_getpid)); +// TODO: glibc 2.30 added gettid() too. #if defined(__BIONIC__) - -// Stop GCC optimizing out our pure function. -/* Must not be static! */ pid_t (*gettid_fp)() = gettid; - -static void BM_unistd_gettid(benchmark::State& state) { - while (state.KeepRunning()) { - gettid_fp(); - } -} -BIONIC_BENCHMARK(BM_unistd_gettid); - +BIONIC_TRIVIAL_BENCHMARK(BM_unistd_gettid, gettid()); #endif - -void BM_unistd_gettid_syscall(benchmark::State& state) { - while (state.KeepRunning()) { - syscall(__NR_gettid); - } -} -BIONIC_BENCHMARK(BM_unistd_gettid_syscall); +BIONIC_TRIVIAL_BENCHMARK(BM_unistd_gettid_syscall, syscall(__NR_gettid)); diff --git a/benchmarks/util.h b/benchmarks/util.h index 0813acc9f..ef4892dac 100644 --- a/benchmarks/util.h +++ b/benchmarks/util.h @@ -41,6 +41,13 @@ static int __attribute__((unused)) EmplaceBenchmark(const std::string& fn_name, #define BIONIC_BENCHMARK_WITH_ARG(n, arg) \ int _bionic_benchmark_##n __attribute__((unused)) = EmplaceBenchmark(std::string(#n), reinterpret_cast<benchmark_func_t>(n), arg) +#define BIONIC_TRIVIAL_BENCHMARK(__name, __expression) \ + static void __name(benchmark::State& state) { \ + for (auto _ : state) { \ + benchmark::DoNotOptimize(__expression); \ + } \ + } \ + BIONIC_BENCHMARK(__name) constexpr auto KB = 1024; diff --git a/benchmarks/wctype_benchmark.cpp b/benchmarks/wctype_benchmark.cpp index f030ddcb6..cdf55686f 100644 --- a/benchmarks/wctype_benchmark.cpp +++ b/benchmarks/wctype_benchmark.cpp @@ -19,58 +19,14 @@ #include <benchmark/benchmark.h> #include "util.h" -static void BM_wctype_towlower_ascii_y(benchmark::State& state) { - for (auto _ : state) { - towlower('X'); - } -} -BIONIC_BENCHMARK(BM_wctype_towlower_ascii_y); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towlower_ascii_y, towlower('X')); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towlower_ascii_n, towlower('x')); -static void BM_wctype_towlower_ascii_n(benchmark::State& state) { - for (auto _ : state) { - towlower('x'); - } -} -BIONIC_BENCHMARK(BM_wctype_towlower_ascii_n); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towlower_unicode_y, towlower(0x0391)); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towlower_unicode_n, towlower(0x03b1)); -static void BM_wctype_towlower_unicode_y(benchmark::State& state) { - for (auto _ : state) { - towlower(0x0391); - } -} -BIONIC_BENCHMARK(BM_wctype_towlower_unicode_y); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towupper_ascii_y, towupper('x')); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towupper_ascii_n, towupper('X')); -static void BM_wctype_towlower_unicode_n(benchmark::State& state) { - for (auto _ : state) { - towlower(0x03b1); - } -} -BIONIC_BENCHMARK(BM_wctype_towlower_unicode_n); - -static void BM_wctype_towupper_ascii_y(benchmark::State& state) { - for (auto _ : state) { - towupper('x'); - } -} -BIONIC_BENCHMARK(BM_wctype_towupper_ascii_y); - -static void BM_wctype_towupper_ascii_n(benchmark::State& state) { - for (auto _ : state) { - towupper('X'); - } -} -BIONIC_BENCHMARK(BM_wctype_towupper_ascii_n); - -static void BM_wctype_towupper_unicode_y(benchmark::State& state) { - for (auto _ : state) { - towupper(0x03b1); - } -} -BIONIC_BENCHMARK(BM_wctype_towupper_unicode_y); - -static void BM_wctype_towupper_unicode_n(benchmark::State& state) { - for (auto _ : state) { - towupper(0x0391); - } -} -BIONIC_BENCHMARK(BM_wctype_towupper_unicode_n); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towupper_unicode_y, towupper(0x03b1)); +BIONIC_TRIVIAL_BENCHMARK(BM_wctype_towupper_unicode_n, towupper(0x0391)); |