summaryrefslogtreecommitdiffstats
path: root/benchmarks
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-12-01 13:12:18 -0800
committerElliott Hughes <enh@google.com>2014-12-01 13:12:18 -0800
commit47dc7c974e71f8d6275288f8137156ce317bf53c (patch)
treefddd8c11b64da013a5aa6ef6afc5f7b89f5655f0 /benchmarks
parent3e6ef3f90285191976a60d7a94287fb0fec1af5d (diff)
downloadbionic-47dc7c974e71f8d6275288f8137156ce317bf53c.zip
bionic-47dc7c974e71f8d6275288f8137156ce317bf53c.tar.gz
bionic-47dc7c974e71f8d6275288f8137156ce317bf53c.tar.bz2
Benchmark fread/fwrite both buffered and unbuffered.
Bug: 18556607 Change-Id: I53905aedcea75fe550d9c423fb701c2c9bf8e831
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/stdio_benchmark.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp
index e899df7..386ea04 100644
--- a/benchmarks/stdio_benchmark.cpp
+++ b/benchmarks/stdio_benchmark.cpp
@@ -25,14 +25,19 @@
Arg(1)->Arg(2)->Arg(3)->Arg(4)->Arg(8)->Arg(16)->Arg(32)->Arg(64)->Arg(512)-> \
Arg(1*KB)->Arg(4*KB)->Arg(8*KB)->Arg(16*KB)->Arg(64*KB)
-static void BM_stdio_fread(int iters, int chunk_size) {
+template <typename Fn>
+static void ReadWriteTest(int iters, int chunk_size, Fn f, bool buffered) {
StopBenchmarkTiming();
FILE* fp = fopen("/dev/zero", "rw");
char* buf = new char[chunk_size];
StartBenchmarkTiming();
+ if (!buffered) {
+ setvbuf(fp, 0, _IONBF, 0);
+ }
+
for (int i = 0; i < iters; ++i) {
- fread(buf, chunk_size, 1, fp);
+ f(buf, chunk_size, 1, fp);
}
StopBenchmarkTiming();
@@ -40,22 +45,23 @@ static void BM_stdio_fread(int iters, int chunk_size) {
delete[] buf;
fclose(fp);
}
-BENCHMARK(BM_stdio_fread)->AT_COMMON_SIZES;
+static void BM_stdio_fread(int iters, int chunk_size) {
+ ReadWriteTest(iters, chunk_size, fread, true);
+}
+BENCHMARK(BM_stdio_fread)->AT_COMMON_SIZES;
static void BM_stdio_fwrite(int iters, int chunk_size) {
- StopBenchmarkTiming();
- FILE* fp = fopen("/dev/zero", "rw");
- char* buf = new char[chunk_size];
- StartBenchmarkTiming();
+ ReadWriteTest(iters, chunk_size, fwrite, true);
+}
+BENCHMARK(BM_stdio_fwrite)->AT_COMMON_SIZES;
- for (int i = 0; i < iters; ++i) {
- fwrite(buf, chunk_size, 1, fp);
- }
+static void BM_stdio_fread_unbuffered(int iters, int chunk_size) {
+ ReadWriteTest(iters, chunk_size, fread, false);
+}
+BENCHMARK(BM_stdio_fread_unbuffered)->AT_COMMON_SIZES;
- StopBenchmarkTiming();
- SetBenchmarkBytesProcessed(int64_t(iters) * int64_t(chunk_size));
- delete[] buf;
- fclose(fp);
+static void BM_stdio_fwrite_unbuffered(int iters, int chunk_size) {
+ ReadWriteTest(iters, chunk_size, fwrite, false);
}
-BENCHMARK(BM_stdio_fwrite)->AT_COMMON_SIZES;
+BENCHMARK(BM_stdio_fwrite_unbuffered)->AT_COMMON_SIZES;