#include <cstdint> | |
#include <iostream> | |
#include <string> | |
#include <boost/timer/timer.hpp> | |
#include <boost/asio/io_service.hpp> | |
#include <boost/asio/strand.hpp> | |
struct handler | |
{ | |
void operator()() | |
{ | |
++counter; | |
} | |
static std::uint32_t counter; | |
}; | |
std::uint32_t handler::counter = 0; | |
int main(int argc, char const* argv[]) | |
{ | |
if (argc < 3) { | |
std::cout << argv[0] << " #task (wrap|dispatch)" << std::endl; | |
return 0; | |
} | |
auto const max_task = std::stoull(argv[1]); | |
namespace asio = boost::asio; | |
asio::io_service io_service{}; | |
asio::io_service::strand strand{io_service}; | |
auto const command = std::string{argv[2]}; | |
if (command == "wrap") { | |
for (auto i = 0ULL; i < max_task; ++i) { | |
io_service.post(strand.wrap(handler{})); | |
} | |
} | |
else if (command == "dispatch") { | |
for (auto i = 0ULL; i < max_task; ++i) { | |
io_service.post([&]{ strand.dispatch(handler{}); }); | |
} | |
} | |
else if (command == "post") { | |
for (auto i = 0ULL; i < max_task; ++i) { | |
io_service.post([&]{ strand.post(handler{}); }); | |
} | |
} | |
else if (command == "strand") { | |
for (auto i = 0ULL; i < max_task; ++i) { | |
strand.post(handler{}); | |
} | |
} | |
{ | |
boost::timer::auto_cpu_timer timer{}; | |
io_service.run(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment