@@ -59,116 +59,114 @@ void BM_ConstructSizeValue(benchmark::State& st, Container, typename Container::
59
59
60
60
template <class Container , class GenInputs >
61
61
void BM_ConstructIterIter (benchmark::State& st, Container, GenInputs gen) {
62
- auto in = gen (st.range (0 ));
63
- const auto begin = in.begin ();
64
- const auto end = in.end ();
65
- benchmark::DoNotOptimize (&in);
66
- while (st.KeepRunning ()) {
67
- Container c (begin, end);
68
- DoNotOptimizeData (c);
69
- }
62
+ auto in = gen (st.range (0 ));
63
+ const auto begin = in.begin ();
64
+ const auto end = in.end ();
65
+ benchmark::DoNotOptimize (&in);
66
+ while (st.KeepRunning ()) {
67
+ Container c (begin, end);
68
+ DoNotOptimizeData (c);
69
+ }
70
70
}
71
71
72
72
template <class Container , class GenInputs >
73
73
void BM_InsertValue (benchmark::State& st, Container c, GenInputs gen) {
74
- auto in = gen (st.range (0 ));
75
- const auto end = in.end ();
76
- while (st.KeepRunning ()) {
77
- c.clear ();
78
- for (auto it = in.begin (); it != end; ++it) {
79
- benchmark::DoNotOptimize (&(*c.insert (*it).first ));
80
- }
81
- benchmark::ClobberMemory ();
74
+ auto in = gen (st.range (0 ));
75
+ const auto end = in.end ();
76
+ while (st.KeepRunning ()) {
77
+ c.clear ();
78
+ for (auto it = in.begin (); it != end; ++it) {
79
+ benchmark::DoNotOptimize (&(*c.insert (*it).first ));
82
80
}
81
+ benchmark::ClobberMemory ();
82
+ }
83
83
}
84
84
85
85
template <class Container , class GenInputs >
86
86
void BM_InsertValueRehash (benchmark::State& st, Container c, GenInputs gen) {
87
- auto in = gen (st.range (0 ));
88
- const auto end = in.end ();
89
- while (st.KeepRunning ()) {
90
- c.clear ();
91
- c.rehash (16 );
92
- for (auto it = in.begin (); it != end; ++it) {
93
- benchmark::DoNotOptimize (&(*c.insert (*it).first ));
94
- }
95
- benchmark::ClobberMemory ();
87
+ auto in = gen (st.range (0 ));
88
+ const auto end = in.end ();
89
+ while (st.KeepRunning ()) {
90
+ c.clear ();
91
+ c.rehash (16 );
92
+ for (auto it = in.begin (); it != end; ++it) {
93
+ benchmark::DoNotOptimize (&(*c.insert (*it).first ));
96
94
}
95
+ benchmark::ClobberMemory ();
96
+ }
97
97
}
98
98
99
-
100
99
template <class Container , class GenInputs >
101
100
void BM_InsertDuplicate (benchmark::State& st, Container c, GenInputs gen) {
102
- auto in = gen (st.range (0 ));
103
- const auto end = in.end ();
104
- c.insert (in.begin (), in.end ());
105
- benchmark::DoNotOptimize (&c);
106
- benchmark::DoNotOptimize (&in);
107
- while (st.KeepRunning ()) {
108
- for (auto it = in.begin (); it != end; ++it) {
109
- benchmark::DoNotOptimize (&(*c.insert (*it).first ));
110
- }
111
- benchmark::ClobberMemory ();
101
+ auto in = gen (st.range (0 ));
102
+ const auto end = in.end ();
103
+ c.insert (in.begin (), in.end ());
104
+ benchmark::DoNotOptimize (&c);
105
+ benchmark::DoNotOptimize (&in);
106
+ while (st.KeepRunning ()) {
107
+ for (auto it = in.begin (); it != end; ++it) {
108
+ benchmark::DoNotOptimize (&(*c.insert (*it).first ));
112
109
}
110
+ benchmark::ClobberMemory ();
111
+ }
113
112
}
114
113
115
-
116
114
template <class Container , class GenInputs >
117
115
void BM_EmplaceDuplicate (benchmark::State& st, Container c, GenInputs gen) {
118
- auto in = gen (st.range (0 ));
119
- const auto end = in.end ();
120
- c.insert (in.begin (), in.end ());
121
- benchmark::DoNotOptimize (&c);
122
- benchmark::DoNotOptimize (&in);
123
- while (st.KeepRunning ()) {
124
- for (auto it = in.begin (); it != end; ++it) {
125
- benchmark::DoNotOptimize (&(*c.emplace (*it).first ));
126
- }
127
- benchmark::ClobberMemory ();
116
+ auto in = gen (st.range (0 ));
117
+ const auto end = in.end ();
118
+ c.insert (in.begin (), in.end ());
119
+ benchmark::DoNotOptimize (&c);
120
+ benchmark::DoNotOptimize (&in);
121
+ while (st.KeepRunning ()) {
122
+ for (auto it = in.begin (); it != end; ++it) {
123
+ benchmark::DoNotOptimize (&(*c.emplace (*it).first ));
128
124
}
125
+ benchmark::ClobberMemory ();
126
+ }
129
127
}
130
128
131
129
template <class Container , class GenInputs >
132
130
static void BM_Find (benchmark::State& st, Container c, GenInputs gen) {
133
- auto in = gen (st.range (0 ));
134
- c.insert (in.begin (), in.end ());
135
- benchmark::DoNotOptimize (&(*c.begin ()));
136
- const auto end = in.data () + in.size ();
137
- while (st.KeepRunning ()) {
138
- for (auto it = in.data (); it != end; ++it) {
139
- benchmark::DoNotOptimize (&(*c.find (*it)));
140
- }
141
- benchmark::ClobberMemory ();
131
+ auto in = gen (st.range (0 ));
132
+ c.insert (in.begin (), in.end ());
133
+ benchmark::DoNotOptimize (&(*c.begin ()));
134
+ const auto end = in.data () + in.size ();
135
+ while (st.KeepRunning ()) {
136
+ for (auto it = in.data (); it != end; ++it) {
137
+ benchmark::DoNotOptimize (&(*c.find (*it)));
142
138
}
139
+ benchmark::ClobberMemory ();
140
+ }
143
141
}
144
142
145
143
template <class Container , class GenInputs >
146
144
static void BM_FindRehash (benchmark::State& st, Container c, GenInputs gen) {
147
- c.rehash (8 );
148
- auto in = gen (st.range (0 ));
149
- c.insert (in.begin (), in.end ());
150
- benchmark::DoNotOptimize (&(*c.begin ()));
151
- const auto end = in.data () + in.size ();
152
- while (st.KeepRunning ()) {
153
- for (auto it = in.data (); it != end; ++it) {
154
- benchmark::DoNotOptimize (&(*c.find (*it)));
155
- }
156
- benchmark::ClobberMemory ();
145
+ c.rehash (8 );
146
+ auto in = gen (st.range (0 ));
147
+ c.insert (in.begin (), in.end ());
148
+ benchmark::DoNotOptimize (&(*c.begin ()));
149
+ const auto end = in.data () + in.size ();
150
+ while (st.KeepRunning ()) {
151
+ for (auto it = in.data (); it != end; ++it) {
152
+ benchmark::DoNotOptimize (&(*c.find (*it)));
157
153
}
154
+ benchmark::ClobberMemory ();
155
+ }
158
156
}
159
157
160
158
template <class Container , class GenInputs >
161
159
static void BM_Rehash (benchmark::State& st, Container c, GenInputs gen) {
162
- auto in = gen (st.range (0 ));
163
- c.max_load_factor (3.0 );
164
- c.insert (in.begin (), in.end ());
165
- benchmark::DoNotOptimize (c);
166
- const auto bucket_count = c.bucket_count ();
167
- while (st.KeepRunning ()) {
168
- c.rehash (bucket_count + 1 );
169
- c.rehash (bucket_count);
170
- benchmark::ClobberMemory ();
171
- }
160
+ auto in = gen (st.range (0 ));
161
+ c.max_load_factor (3.0 );
162
+ c.insert (in.begin (), in.end ());
163
+ benchmark::DoNotOptimize (c);
164
+ const auto bucket_count = c.bucket_count ();
165
+ while (st.KeepRunning ()) {
166
+ c.rehash (bucket_count + 1 );
167
+ c.rehash (bucket_count);
168
+ benchmark::ClobberMemory ();
169
+ }
172
170
}
173
171
174
172
} // end namespace ContainerBenchmarks
0 commit comments