diff options
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); + |