diff options
author | Anders Lewis <agloo@google.com> | 2017-08-08 18:29:51 -0700 |
---|---|---|
committer | Anders Lewis <agloo@google.com> | 2017-08-09 15:26:37 -0700 |
commit | ac4f4b43a3d19f40fc1138c5f78a3d5afd535935 (patch) | |
tree | 383382ddc413b182c7b84cab5c2e47004bfd9470 /benchmarks/stdio_benchmark.cpp | |
parent | a7b0f8899790198cd9e72950f481679fe31e1a92 (diff) |
Add musl benchmarks.
Test: Unit tests.
Change-Id: Ifb2911825f84b95fe64a803bfabd32fb81210eae
Diffstat (limited to 'benchmarks/stdio_benchmark.cpp')
-rw-r--r-- | benchmarks/stdio_benchmark.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp index 756a698bb..a1ca60e8a 100644 --- a/benchmarks/stdio_benchmark.cpp +++ b/benchmarks/stdio_benchmark.cpp @@ -63,9 +63,10 @@ void BM_stdio_fwrite_unbuffered(benchmark::State& state) { BIONIC_BENCHMARK(BM_stdio_fwrite_unbuffered); static void FopenFgetsFclose(benchmark::State& state, bool no_locking) { - char buf[1024]; + size_t nbytes = state.range(0); + char buf[nbytes]; while (state.KeepRunning()) { - FILE* fp = fopen("/proc/version", "re"); + FILE* fp = fopen("/dev/zero", "re"); if (no_locking) __fsetlocking(fp, FSETLOCKING_BYCALLER); if (fgets(buf, sizeof(buf), fp) == nullptr) abort(); fclose(fp); @@ -81,3 +82,27 @@ void BM_stdio_fopen_fgets_fclose_no_locking(benchmark::State& state) { FopenFgetsFclose(state, true); } BIONIC_BENCHMARK(BM_stdio_fopen_fgets_fclose_no_locking); + +static void FopenFgetcFclose(benchmark::State& state, bool no_locking) { + size_t nbytes = state.range(0); + while (state.KeepRunning()) { + FILE* fp = fopen("/dev/zero", "re"); + if (no_locking) __fsetlocking(fp, FSETLOCKING_BYCALLER); + volatile int c __attribute__((unused)); + for (size_t i = 0; i < nbytes; ++i) { + c = fgetc(fp); + } + fclose(fp); + } +} + +static void BM_stdio_fopen_fgetc_fclose_locking(benchmark::State& state) { + FopenFgetcFclose(state, false); +} +BIONIC_BENCHMARK(BM_stdio_fopen_fgetc_fclose_locking); + +void BM_stdio_fopen_fgetc_fclose_no_locking(benchmark::State& state) { + FopenFgetcFclose(state, true); +} +BIONIC_BENCHMARK(BM_stdio_fopen_fgetc_fclose_no_locking); + |