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

Side by Side Diff: base/containers/flat_set_perftest.cc

Issue 2854353002: Flat Tree Perftest
Patch Set: Smarter Stable Sort 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/BUILD.gn ('k') | base/containers/flat_tree.h » ('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 "base/containers/flat_set.h"
6
7 #include <algorithm>
8 #include <numeric>
9 #include <random>
10 #include <string>
11 #include <vector>
12
13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
18
19 namespace base {
20 enum class TestOrder { ASCENDING, DESCENDING, INTERLEAVED, RANDOM };
21
22 std::string to_string(TestOrder order) {
23 switch (order) {
24 case TestOrder::ASCENDING:
25 return "ascending";
26 case TestOrder::DESCENDING:
27 return "descending";
28 case TestOrder::INTERLEAVED:
29 return "interleaved";
30 case TestOrder::RANDOM:
31 return "random";
32 default:
33 return "";
34 }
35 }
36
37 std::string to_string(RangeInsertMethod method) {
38 switch (method) {
39 case RangeInsertMethod::ONE_BY_ONE:
40 return "One By One";
41 case RangeInsertMethod::STABLE_SORT_ALL:
42 return "Stable Sort All";
43 case RangeInsertMethod::STABLE_SORT_SMART:
44 return "Stable Sort Smart";
45 case RangeInsertMethod::STABLE_SORT_SMARTER:
46 return "Stable Sort Smarter";
47 default:
48 return "";
49 }
50 }
51
52 std::vector<int> GetInputs(int length, TestOrder order, int start = 0) {
53 std::vector<int> inputs(length);
54 std::iota(std::begin(inputs), std::end(inputs), start);
55
56 switch (order) {
57 case TestOrder::ASCENDING:
58 break;
59 case TestOrder::DESCENDING:
60 std::reverse(std::begin(inputs), std::end(inputs));
61 break;
62 case TestOrder::INTERLEAVED:
63 for (int i = 0; i < length / 2; i += 2)
64 std::swap(inputs[i], inputs[length - 1 - i]);
65 break;
66 case TestOrder::RANDOM: {
67 std::random_device rd;
68 std::mt19937 g(rd());
69 std::shuffle(std::begin(inputs), std::end(inputs), g);
70 break;
71 }
72 }
73
74 return inputs;
75 }
76
77 void test_range_insertion(int initial_size,
78 int n_items,
79 int pct_overlap,
80 TestOrder order,
81 RangeInsertMethod method) {
82 flat_set<int> set(GetInputs(initial_size, TestOrder::ASCENDING),
83 KEEP_FIRST_OF_DUPES);
84 std::string description = "Initial Size: " + std::to_string(initial_size) +
85 "\tNumber of Items: " + std::to_string(n_items) +
86 "\tPct Overlap: " + std::to_string(pct_overlap) +
87 "\tTestOrder: " + to_string(order) +
88 "\tMethod: " + to_string(method);
89 int input_start = std::max(0.0, initial_size - pct_overlap / 100.0 * n_items);
90 std::vector<int> inputs = GetInputs(n_items, order, input_start);
91 TimeTicks start = TimeTicks::Now();
92 set.insert(inputs.begin(), inputs.end(), method);
93 TimeTicks end = TimeTicks::Now();
94 double duration = (end - start).InMicroseconds();
95 perf_test::PrintResult("RangeInsertionTest", "", description, duration, "us",
96 true);
97 }
98
99 TEST(FlatSetPerfTest, RangeInsertionTest) {
100 for (int i = 0; i < 16; ++i) {
101 for (int n = 0; n < 16; ++n) {
102 for (int o = 0; o <= 10; ++o) {
103 for (int t = 0; t < 4; ++t) {
104 for (int m = 0; m < 4; ++m) {
105 test_range_insertion(1 << i, 1 << n, o * 10,
106 static_cast<TestOrder>(t),
107 static_cast<RangeInsertMethod>(m));
108 }
109 }
110 }
111 }
112 }
113 }
114
115 } // namespace base
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | base/containers/flat_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698