Skip to content

Commit d1c65b3

Browse files
committed
implement skipping inapplicable tests
1 parent 3b9a395 commit d1c65b3

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

bench/bench.cpp

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,13 @@ class any_impl
124124
{
125125
if( !extra.empty() )
126126
extra += '+';
127-
128127
extra += "file IO";
129128
}
130129

131130
if( is_pool )
132131
{
133-
if( !extra.empty() )
132+
if( !extra.empty() )
134133
extra = '+' + extra;
135-
136134
extra = "pool" + extra;
137135
}
138136

@@ -179,8 +177,8 @@ class any_impl
179177
}
180178
};
181179

182-
using impl_list = std::vector<
183-
std::unique_ptr<any_impl const>>;
180+
using impl_ptr = std::unique_ptr<any_impl const>;
181+
using impl_list = std::vector<impl_ptr>;
184182

185183
std::string
186184
load_file(char const* path)
@@ -263,17 +261,34 @@ bench(
263261
std::size_t repeat = 1;
264262
auto const f = [&]
265263
{
266-
if(verb == "Serialize")
267-
return vi[j]->serialize(vf[i].text, repeat);
268-
else if( vi[j]->with_file_io() )
269-
return vi[j]->parse(vf[i], repeat);
270-
else
271-
return vi[j]->parse(vf[i].text, repeat);
264+
if(verb == "Parse")
265+
{
266+
if( vi[j]->with_file_io() )
267+
return vi[j]->parse(vf[i], repeat);
268+
else
269+
return vi[j]->parse(vf[i].text, repeat);
270+
}
272271

273-
return clock_type::duration();
272+
BOOST_ASSERT( verb == "Serialize" );
273+
if( vi[j]->with_file_io() )
274+
return clock_type::duration::zero();
275+
else
276+
return vi[j]->serialize(vf[i].text, repeat);
274277
};
275-
// helps with the caching, which reduces noise
276-
f();
278+
// helps with the caching, which reduces noise; also, we determine
279+
// if this configuration should be skipped altogether
280+
auto const elapsed = f();
281+
if( elapsed == std::chrono::milliseconds::zero() )
282+
{
283+
print_prefix(dout, vf[i], *vi[j], verb)
284+
<< "," << "N/A"
285+
<< "," << "N/A"
286+
<< "," << "N/A"
287+
<< "\n";
288+
print_prefix(strout, vf[i], *vi[j], verb)
289+
<< "," << "N/A" << "\n";
290+
continue;
291+
}
277292

278293
repeat = 1000;
279294
for(unsigned k = 0; k < Trials; ++k)
@@ -282,7 +297,7 @@ bench(
282297
result.calls *= repeat;
283298
result.mbs = megabytes_per_second(
284299
vf[i], result.calls, result.millis);
285-
print_prefix(dout, vf[i], *vi[j], verb )
300+
print_prefix(dout, vf[i], *vi[j], verb)
286301
<< "," << result.calls
287302
<< "," << result.millis
288303
<< "," << result.mbs
@@ -296,43 +311,33 @@ bench(
296311
std::sort(
297312
trial.begin(),
298313
trial.end(),
299-
[]( sample const& lhs,
300-
sample const& rhs)
314+
[](sample const& lhs, sample const& rhs)
301315
{
302316
return lhs.mbs < rhs.mbs;
303317
});
304318
if(Trials >= 6)
305319
{
306320
// discard worst 2
307-
trial.erase(
308-
trial.begin(),
309-
trial.begin() + 2);
321+
trial.erase(trial.begin(), trial.begin() + 2);
310322
// discard best 1
311-
trial.resize( trial.size() - 1 );
312-
323+
trial.resize(trial.size() - 1);
313324
}
314325
else if(Trials > 3)
315326
{
316-
trial.erase(
317-
trial.begin(),
318-
trial.begin() + Trials - 3);
327+
trial.erase(trial.begin(), trial.begin() + Trials - 3);
319328
}
320329
// average
321-
auto const calls =
322-
std::accumulate(
330+
auto const calls = std::accumulate(
323331
trial.begin(), trial.end(),
324332
std::size_t{},
325-
[]( std::size_t lhs,
326-
sample const& rhs)
333+
[](std::size_t lhs, sample const& rhs)
327334
{
328335
return lhs + rhs.calls;
329336
});
330-
auto const millis =
331-
std::accumulate(
337+
auto const millis = std::accumulate(
332338
trial.begin(), trial.end(),
333339
std::size_t{},
334-
[]( std::size_t lhs,
335-
sample const& rhs)
340+
[](std::size_t lhs, sample const& rhs)
336341
{
337342
return lhs + rhs.millis;
338343
});
@@ -1004,7 +1009,7 @@ bool add_impl(impl_list & vi, char kind, char alloc, char io, char num)
10041009
bool const with_file_io = io == 'y';
10051010
bool const is_pool = alloc == 'p';
10061011

1007-
std::unique_ptr<any_impl const> impl;
1012+
impl_ptr impl;
10081013
switch( kind )
10091014
{
10101015
case 'b':
@@ -1140,19 +1145,18 @@ main(
11401145
for( char io: s_file_io )
11411146
add_impl( vi, impl, alloc, io, num );
11421147

1148+
// remove duplicate implementations
11431149
std::sort(
11441150
vi.begin(),
11451151
vi.end(),
1146-
[](std::unique_ptr<any_impl const> const& l,
1147-
std::unique_ptr<any_impl const> const& r)
1152+
[](impl_ptr const& l, impl_ptr const& r)
11481153
{
11491154
return l->name() < r->name();
11501155
});
11511156
auto const it = std::unique(
11521157
vi.begin(),
11531158
vi.end(),
1154-
[](std::unique_ptr<any_impl const> const& l,
1155-
std::unique_ptr<any_impl const> const& r)
1159+
[](impl_ptr const& l, impl_ptr const& r)
11561160
{
11571161
return l->name() == r->name();
11581162
});

0 commit comments

Comments
 (0)