aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/stdio_benchmark.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-08-10 23:44:04 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-08-10 23:44:04 +0000
commit73c3be22199a42bed53245b9b648e276de0b6422 (patch)
tree6c592e09bd57616bd84d32efce96645ee8a25094 /benchmarks/stdio_benchmark.cpp
parentcf764c05e43921e4d3f927a5eaca1c6ecafe046b (diff)
parentac4f4b43a3d19f40fc1138c5f78a3d5afd535935 (diff)
downloadandroid_bionic-73c3be22199a42bed53245b9b648e276de0b6422.tar.gz
android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.tar.bz2
android_bionic-73c3be22199a42bed53245b9b648e276de0b6422.zip
Merge "Add musl benchmarks."
Diffstat (limited to 'benchmarks/stdio_benchmark.cpp')
-rw-r--r--benchmarks/stdio_benchmark.cpp29
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);
+