Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1967)

Unified Diff: base/containers/containers_benchmarks.cc

Issue 2865663003: Adding Google benchmarking library. (Closed)
Patch Set: Sketch. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/DEPS ('k') | base/test/run_all_base_microbenchmarks.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/containers/containers_benchmarks.cc
diff --git a/base/containers/containers_benchmarks.cc b/base/containers/containers_benchmarks.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fa22ad6917efcfeccec62e8c531597cfaaf46b81
--- /dev/null
+++ b/base/containers/containers_benchmarks.cc
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+#include <array>
+#include <iterator>
+#include <numeric>
+#include <set>
+
+#include "base/containers/flat_set.h"
+#include "third_party/google_benchmark/include/benchmark/benchmark.h"
+
+namespace {
+
+template <typename>
+struct TypeTag {};
+
+base::flat_set<int> GenerateSet(const std::vector<int>& input,
+ TypeTag<base::flat_set<int>>) {
+ return {input.begin(), input.end(), base::KEEP_FIRST_OF_DUPES};
+}
+
+std::set<int> GenerateSet(const std::vector<int>& input,
+ TypeTag<std::set<int>>) {
+ return {input.begin(), input.end()};
+}
+
+template <typename Set>
+void InsertInTheBeginingByOne(benchmark::State& state) {
+ constexpr int kNewElementsCount = 10;
+ std::array<int, kNewElementsCount> new_elements;
+ std::iota(new_elements.begin(), new_elements.end(), 0);
+ std::vector<int> already_in(state.range(0));
+ std::iota(already_in.begin(), already_in.end(), kNewElementsCount);
+
+ while (state.KeepRunning()) {
+ state.PauseTiming();
+ Set test_set = GenerateSet(already_in, TypeTag<Set>{});
+ state.ResumeTiming();
+ std::copy(new_elements.begin(), new_elements.end(),
+ std::inserter(test_set, test_set.begin()));
+ }
+}
+
+constexpr int kMinSize = 0;
+constexpr int kMaxSize = 1 << 10;
+
+BENCHMARK_TEMPLATE(InsertInTheBeginingByOne, std::set<int>)
+ ->Range(kMinSize, kMaxSize);
+BENCHMARK_TEMPLATE(InsertInTheBeginingByOne, base::flat_set<int>)
+ ->Range(kMinSize, kMaxSize);
+
+} // namespace
« no previous file with comments | « base/DEPS ('k') | base/test/run_all_base_microbenchmarks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698