From 4f802227dd2f0faf82006dca10189e4af25699fa Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Sun, 19 Aug 2012 12:29:15 -0700 Subject: [PATCH] folly: add a simple benchmark for Histogram::addValue() Summary: I wrote this an an example for the BENCHMARK_NAMED_PARAM() comments in D527040, and figured I might as well check it in as a real benchmark. Test Plan: Here's the output: ====================================================================== folly/test/HistogramBenchmark.cpp relative time/iter iters/s ====================================================================== addValue(0_to_100) 15.43ns 64.81M addValue(0_to_1000) 15.45ns 64.70M addValue(5k_to_20k) 15.46ns 64.67M ====================================================================== Reviewed By: rajat@fb.com FB internal diff: D552875 --- folly/test/HistogramBenchmark.cpp | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 folly/test/HistogramBenchmark.cpp diff --git a/folly/test/HistogramBenchmark.cpp b/folly/test/HistogramBenchmark.cpp new file mode 100644 index 00000000..e463f8d1 --- /dev/null +++ b/folly/test/HistogramBenchmark.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2012 Facebook, Inc. + * + * 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 "folly/Histogram.h" + +#include + +#include "folly/Benchmark.h" +#include "folly/Foreach.h" + +using folly::Histogram; + +void addValue(uint n, int64_t bucketSize, int64_t min, int64_t max) { + Histogram hist(bucketSize, min, max); + int64_t num = min; + FOR_EACH_RANGE (i, 0, n) { + hist.addValue(num); + ++num; + if (num > max) { num = min; } + } +} + +BENCHMARK_NAMED_PARAM(addValue, 0_to_100, 1, 0, 100); +BENCHMARK_NAMED_PARAM(addValue, 0_to_1000, 10, 0, 1000); +BENCHMARK_NAMED_PARAM(addValue, 5k_to_20k, 250, 5000, 20000); + +int main(int argc, char *argv[]) { + google::ParseCommandLineFlags(&argc, &argv, true); + folly::runBenchmarks(); + return 0; +} -- 2.34.1