Add musl benchmarks.
Test: Unit tests.
Change-Id: Ifb2911825f84b95fe64a803bfabd32fb81210eae
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp
index 756a698..a1ca60e 100644
--- a/benchmarks/stdio_benchmark.cpp
+++ b/benchmarks/stdio_benchmark.cpp
@@ -63,9 +63,10 @@
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 @@
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);
+