Skip to content

Commit

Permalink
update recursive_wrapper and unique_ptr tests to accept <num-iter> arg
Browse files Browse the repository at this point in the history
  • Loading branch information
artemp committed May 19, 2014
1 parent b4abfa5 commit edcb444
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
25 changes: 22 additions & 3 deletions recursive_wrapper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct binary_op
expression left; // variant instantiated here...
expression right;

binary_op( expression const& lhs, expression const& rhs )
: left(lhs), right(rhs)
binary_op( expression && lhs, expression && rhs )
: left(std::move(lhs)), right(std::move(rhs))
{
}
};
Expand Down Expand Up @@ -100,13 +100,32 @@ struct to_string : public util::static_visitor<std::string>

int main (int argc, char** argv)
{

if (argc != 2)
{
std::cerr << "Usage" << argv[0] << " <num-iter>" << std::endl;
return EXIT_FAILURE;
}

std::size_t const NUM_ITER = std::stoll(argv[1]);

test::expression result(util::recursive_wrapper<test::binary_op<test::sub> >(
test::binary_op<test::sub>(
util::recursive_wrapper<test::binary_op<test::add> >(
test::binary_op<test::add>(10,5)),7)));
test::binary_op<test::add>(2,3)),10)));

std::cerr << "TYPE OF RESULT-> " << util::apply_visitor(result, test::test()) << std::endl;

{
boost::timer::auto_cpu_timer t;
std::size_t total = 0;
for (int i = 0; i < NUM_ITER; ++i)
{
total +=util::apply_visitor(result, test::calculator());
}
std::cerr << "total=" << total << std::endl;
}

std::cerr << util::apply_visitor(result, test::to_string()) << "=" << util::apply_visitor(result, test::calculator()) << std::endl;


Expand Down
21 changes: 19 additions & 2 deletions unique_ptr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,29 @@ struct to_string : public util::static_visitor<std::string>

int main (int argc, char** argv)
{
if (argc != 2)
{
std::cerr << "Usage" << argv[0] << " <num-iter>" << std::endl;
return EXIT_FAILURE;
}

std::size_t const NUM_ITER = std::stoll(argv[1]);

test::expression sum(std::unique_ptr<test::binary_op<test::add>>(new test::binary_op<test::add>(2,3)));
test::expression result(std::unique_ptr<test::binary_op<test::sub>>(new test::binary_op<test::sub>(std::move(sum),10)));
std::cerr << "TYPE OF RESULT-> " << util::apply_visitor(result, test::test()) << std::endl;
for (int i=0; i<10;++i)

{
std::cerr << util::apply_visitor(result, test::to_string()) << "=" << util::apply_visitor(result, test::calculator()) << std::endl;
boost::timer::auto_cpu_timer t;
std::size_t total = 0;
for (int i = 0; i < NUM_ITER; ++i)
{
total +=util::apply_visitor(result, test::calculator());
}
std::cerr << "total=" << total << std::endl;
}

std::cerr << util::apply_visitor(result, test::to_string()) << "=" << util::apply_visitor(result, test::calculator()) << std::endl;

return EXIT_SUCCESS;
}

0 comments on commit edcb444

Please sign in to comment.