Created
September 19, 2019 05:34
-
-
Save lizan/077b3ec6be86ad8515e5862e4327aed8 to your computer and use it in GitHub Desktop.
hash comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: this should be run with --compilation_mode=opt, and would benefit from a | |
// quiescent system with disabled cstate power management. | |
#include "envoy/config/bootstrap/v2/bootstrap.pb.h" | |
#include "envoy/config/bootstrap/v2/bootstrap.pb.validate.h" | |
#include "common/protobuf/utility.h" | |
#include "absl/strings/string_view.h" | |
#include "benchmark/benchmark.h" | |
namespace Envoy { | |
static ProtobufTypes::MessagePtr messageToHash(uint32_t size) { | |
envoy::config::bootstrap::v2::Bootstrap bootstrap; | |
bootstrap.set_flags_path("foo"); | |
bootstrap.mutable_node(); | |
for (uint32_t i = 0; i < size; ++i) { | |
bootstrap.mutable_static_resources()->add_listeners()->set_name(absl::StrCat("http", i)); | |
bootstrap.mutable_static_resources()->add_clusters()->set_name(absl::StrCat("cluster", i)); | |
(*bootstrap.mutable_node()->mutable_metadata()->mutable_fields())[absl::StrCat("key", i)].set_string_value("value"); | |
} | |
return std::make_unique<envoy::config::bootstrap::v2::Bootstrap>(std::move(bootstrap)); | |
} | |
static void BM_MessageUtilHash(benchmark::State& state) { | |
ProtobufTypes::MessagePtr message = messageToHash(state.range(0)); | |
for (auto _ : state) { | |
benchmark::DoNotOptimize(MessageUtil::hash(*message)); | |
} | |
} | |
BENCHMARK(BM_MessageUtilHash)->Arg(0)->Arg(1)->Arg(5)->Arg(10); | |
static void BM_MessageUtilStableHash(benchmark::State& state) { | |
ProtobufTypes::MessagePtr message = messageToHash(state.range(0)); | |
for (auto _ : state) { | |
benchmark::DoNotOptimize(MessageUtil::anyStableHash(*message)); | |
} | |
} | |
BENCHMARK(BM_MessageUtilStableHash)->Arg(0)->Arg(1)->Arg(5)->Arg(10); | |
} // namespace Envoy | |
// Boilerplate main(), which discovers benchmarks in the same file and runs them. | |
int main(int argc, char** argv) { | |
benchmark::Initialize(&argc, argv); | |
if (benchmark::ReportUnrecognizedArguments(argc, argv)) { | |
return 1; | |
} | |
benchmark::RunSpecifiedBenchmarks(); | |
} | |
/* | |
Run on (8 X 2200 MHz CPU s) | |
CPU Caches: | |
L1 Data 32K (x4) | |
L1 Instruction 32K (x4) | |
L2 Unified 256K (x4) | |
L3 Unified 56320K (x1) | |
Load Average: 2.91, 1.80, 0.84 | |
---------------------------------------------------------------------- | |
Benchmark Time CPU Iterations | |
---------------------------------------------------------------------- | |
BM_MessageUtilHash/0 131 ns 131 ns 4947779 | |
BM_MessageUtilHash/1 717 ns 717 ns 982916 | |
BM_MessageUtilHash/5 2362 ns 2362 ns 288239 | |
BM_MessageUtilHash/10 5030 ns 5030 ns 100000 | |
BM_MessageUtilStableHash/0 942 ns 942 ns 614300 | |
BM_MessageUtilStableHash/1 5660 ns 5660 ns 123849 | |
BM_MessageUtilStableHash/5 16667 ns 16665 ns 41601 | |
BM_MessageUtilStableHash/10 29361 ns 29357 ns 23834 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment