aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2016-09-30 19:42:53 -0700
committerDan Willemsen <dwillemsen@google.com>2016-10-01 12:27:16 -0700
commit9862c2a1dc844d431cf3f9cca41603362cc077c9 (patch)
tree7318ea98fd6c2e421d7b69021196c368dd3d390f
parent5e45e973c38c92c42cc86aa5dafeca13e6823b5f (diff)
downloadplatform_build_kati-9862c2a1dc844d431cf3f9cca41603362cc077c9.tar.gz
platform_build_kati-9862c2a1dc844d431cf3f9cca41603362cc077c9.tar.bz2
platform_build_kati-9862c2a1dc844d431cf3f9cca41603362cc077c9.zip
Add simple benchmark for RunCommand
Change-Id: I7f3aabdd8fc01f9ddbcf23e586b6f5e81ab8cbce
-rw-r--r--Android.bp13
-rw-r--r--Makefile.ckati3
-rw-r--r--fileutil_bench.cc39
3 files changed, 54 insertions, 1 deletions
diff --git a/Android.bp b/Android.bp
index 91c2972..5dd8ef5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -79,3 +79,16 @@ cc_test_host {
},
},
}
+
+cc_benchmark_host {
+ name: "ckati_fileutil_bench",
+ srcs: [
+ "fileutil_bench.cc",
+ ],
+ whole_static_libs: ["libckati"],
+ target: {
+ linux: {
+ host_ldlibs: ["-lrt", "-lpthread"],
+ },
+ },
+}
diff --git a/Makefile.ckati b/Makefile.ckati
index df4c6a5..e4067bb 100644
--- a/Makefile.ckati
+++ b/Makefile.ckati
@@ -57,7 +57,8 @@ KATI_CXX_GENERATED_SRCS := \
KATI_CXX_SRCS := $(addprefix $(KATI_SRC_PATH)/,$(KATI_CXX_SRCS))
KATI_CXX_TEST_SRCS := \
$(wildcard $(KATI_SRC_PATH)/*_test.cc) \
- $(wildcard $(KATI_SRC_PATH)/*_bench.cc)
+ $(filter-out $(KATI_SRC_PATH)/fileutil_bench.cc,\
+ $(wildcard $(KATI_SRC_PATH)/*_bench.cc))
KATI_CXX_OBJS := $(patsubst $(KATI_SRC_PATH)/%.cc,$(KATI_INTERMEDIATES_PATH)/%.o,\
$(KATI_CXX_SRCS))
diff --git a/fileutil_bench.cc b/fileutil_bench.cc
new file mode 100644
index 0000000..dc07d9a
--- /dev/null
+++ b/fileutil_bench.cc
@@ -0,0 +1,39 @@
+// Copyright 2016 Google Inc. All rights reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "fileutil.h"
+#include <benchmark/benchmark.h>
+#include <cstdio>
+
+static void BM_RunCommand(benchmark::State& state) {
+ std::string shell = "/bin/bash -c";
+ std::string cmd = "echo $((1+3))";
+ while (state.KeepRunning()) {
+ std::string result;
+ RunCommand(shell, cmd, RedirectStderr::NONE, &result);
+ }
+}
+BENCHMARK(BM_RunCommand);
+
+static void BM_RunCommand_ComplexShell(benchmark::State& state) {
+ std::string shell = "/bin/bash -c";
+ std::string cmd = "echo $((1+3))";
+ while (state.KeepRunning()) {
+ std::string result;
+ RunCommand(shell, cmd, RedirectStderr::NONE, &result);
+ }
+}
+BENCHMARK(BM_RunCommand_ComplexShell);
+
+BENCHMARK_MAIN();