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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/DEPS ('k') | base/test/run_all_base_microbenchmarks.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <algorithm>
6 #include <array>
7 #include <iterator>
8 #include <numeric>
9 #include <set>
10
11 #include "base/containers/flat_set.h"
12 #include "third_party/google_benchmark/include/benchmark/benchmark.h"
13
14 namespace {
15
16 template <typename>
17 struct TypeTag {};
18
19 base::flat_set<int> GenerateSet(const std::vector<int>& input,
20 TypeTag<base::flat_set<int>>) {
21 return {input.begin(), input.end(), base::KEEP_FIRST_OF_DUPES};
22 }
23
24 std::set<int> GenerateSet(const std::vector<int>& input,
25 TypeTag<std::set<int>>) {
26 return {input.begin(), input.end()};
27 }
28
29 template <typename Set>
30 void InsertInTheBeginingByOne(benchmark::State& state) {
31 constexpr int kNewElementsCount = 10;
32 std::array<int, kNewElementsCount> new_elements;
33 std::iota(new_elements.begin(), new_elements.end(), 0);
34 std::vector<int> already_in(state.range(0));
35 std::iota(already_in.begin(), already_in.end(), kNewElementsCount);
36
37 while (state.KeepRunning()) {
38 state.PauseTiming();
39 Set test_set = GenerateSet(already_in, TypeTag<Set>{});
40 state.ResumeTiming();
41 std::copy(new_elements.begin(), new_elements.end(),
42 std::inserter(test_set, test_set.begin()));
43 }
44 }
45
46 constexpr int kMinSize = 0;
47 constexpr int kMaxSize = 1 << 10;
48
49 BENCHMARK_TEMPLATE(InsertInTheBeginingByOne, std::set<int>)
50 ->Range(kMinSize, kMaxSize);
51 BENCHMARK_TEMPLATE(InsertInTheBeginingByOne, base::flat_set<int>)
52 ->Range(kMinSize, kMaxSize);
53
54 } // namespace
OLDNEW
« 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