Add an end-to-end property benchmark.
This change adds an end-to-end property benchmark that finds each
property currently accessible on the system via
__system_property_find().
Test: run this benchmark
Change-Id: I7d20cc9caf36bf3650c3bb3f58500b7df09a908a
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index 9868765..0f1a110 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -20,6 +20,7 @@
#include <unistd.h>
#include <string>
+#include <vector>
#include <android-base/test_utils.h>
@@ -192,4 +193,30 @@
}
BIONIC_BENCHMARK_WITH_ARG(BM_property_serial, "NUM_PROPS");
+// This benchmarks find the actual properties currently set on the system and accessible by the
+// user that runs this benchmark (aka this is best run as root). It is not comparable between
+// devices, nor even boots, but is useful to understand the the real end-to-end speed, including
+// costs to find the correct property file within /dev/__properties__.
+static void BM_property_find_real(benchmark::State& state) {
+ std::vector<std::string> properties;
+ __system_property_foreach(
+ [](const prop_info* pi, void* cookie) {
+ __system_property_read_callback(pi,
+ [](void* cookie, const char* name, const char*, unsigned) {
+ auto properties =
+ reinterpret_cast<std::vector<std::string>*>(cookie);
+ properties->emplace_back(name);
+ },
+ cookie);
+ },
+ &properties);
+
+ while (state.KeepRunning()) {
+ for (const auto& property : properties) {
+ __system_property_find(property.c_str());
+ }
+ }
+}
+BIONIC_BENCHMARK(BM_property_find_real);
+
#endif // __BIONIC__