Skip to content

Commit

Permalink
interleave test runs to ensure first run penalty does not murky the r…
Browse files Browse the repository at this point in the history
…esults
  • Loading branch information
Dane Springmeyer committed Feb 11, 2014
1 parent df1d00c commit 969a346
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sizes: Makefile variant.hpp
@$(CXX) -o ./test/boost-variant ./test/boost-variant.cpp -I./ $(COMMON_FLAGS) $(CXXFLAGS) && du -h ./test/boost-variant

test: test-variant
./test-variant 1000000
./test-variant 5000000

clean:
rm -f ./test-variant
Expand Down
92 changes: 48 additions & 44 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,60 +69,64 @@ struct dummy2
V & v_;
};

int main (int argc, char** argv)
void run_boost_test(std::size_t runs)
{
if (argc!=2)
std::cerr << "boost variant: ";
boost::timer::auto_cpu_timer t;
test::Holder<boost::variant<int,double,std::string>> h;
h.data.reserve(runs);
for (std::size_t i=0; i< runs;++i)
{
std::cerr << "Usage:" << argv[0] << " <num-runs>" << std::endl;
return 1;
h.append_move(std::string(TEXT));
h.append_move(123);
h.append_move(3.14159);
}
const std::size_t NUM_RUNS = static_cast<std::size_t>(std::stol(argv[1]));

#if 1
boost::variant<int,double,std::string> v;
for (auto const& v2 : h.data)
{
boost::timer::auto_cpu_timer t;
test::Holder<boost::variant<int,double,std::string>> h;
h.data.reserve(NUM_RUNS);
for (std::size_t i=0; i< NUM_RUNS;++i)
{
h.append_move(std::string(TEXT));
h.append_move(123);
h.append_move(3.14159);
}

std::cerr << h.data.size() << std::endl;
boost::variant<int,double,std::string> v;
for (auto const& v2 : h.data)
{
dummy<boost::variant<int,double,std::string> > d(v);
boost::apply_visitor(d, v2);
}
dummy<boost::variant<int,double,std::string> > d(v);
boost::apply_visitor(d, v2);
}
#endif
}

#if 1
void run_variant_test(std::size_t runs)
{
std::cerr << "custom variant: ";
boost::timer::auto_cpu_timer t;
test::Holder<util::variant<int,double,std::string> > h;
h.data.reserve(runs);
for (std::size_t i=0; i< runs;++i)
{
boost::timer::auto_cpu_timer t;
test::Holder<util::variant<int,double,std::string> > h;
h.data.reserve(NUM_RUNS);
for (std::size_t i=0; i< NUM_RUNS;++i)
{
h.append_move(std::string(TEXT));
h.append_move(123);
h.append_move(3.14159);

}
std::cerr << h.data.size() << std::endl;
util::variant<int,double,std::string> v;
for (auto const& v2 : h.data)
{
dummy2<util::variant<int,double,std::string> > d(v);
util::apply_visitor(v2, d);
}
h.append_move(std::string(TEXT));
h.append_move(123);
h.append_move(3.14159);
}
#endif

#if 1
util::variant<int,double,std::string> v;
for (auto const& v2 : h.data)
{
dummy2<util::variant<int,double,std::string> > d(v);
util::apply_visitor(v2, d);
}
}

int main (int argc, char** argv)
{
if (argc!=2)
{
std::cerr << "Usage:" << argv[0] << " <num-runs>" << std::endl;
return 1;
}
const std::size_t NUM_RUNS = static_cast<std::size_t>(std::stol(argv[1]));

run_variant_test(NUM_RUNS);
run_boost_test(NUM_RUNS);
run_variant_test(NUM_RUNS);
run_boost_test(NUM_RUNS);
run_variant_test(NUM_RUNS);
run_boost_test(NUM_RUNS);
#if 0

std::cerr << util::detail::type_traits<bool, bool, int, double, std::string>::id << std::endl;
std::cerr << util::detail::type_traits<int, bool, int, double, std::string>::id << std::endl;
Expand Down

0 comments on commit 969a346

Please sign in to comment.