#define BOOST_TEST_MODULE TestPerformance #include #include #include #include #include #include #include #include #include std::atomic_long count; bool run = true; static const int THREADS = 200; static const int CALLS = 2000; static void test(Gentoo::PortagePrx p, const Gentoo::Packages & pkgs) { boost::random::mt19937 rng; boost::random::uniform_int_distribution<> pid(0, pkgs.size() - 1); unsigned int myCount = 0; while (run) { p->getPackage(pkgs[pid(rng)]->packageid); myCount += 1; } count += myCount; } BOOST_AUTO_TEST_CASE( perf ) { Ice::StringSeq _args; _args.push_back("--Ice.ThreadPool.Client.Size=50"); _args.push_back("--Ice.ThreadPool.Client.SizeMax=50"); Ice::CommunicatorPtr ic = Ice::initialize(_args, Ice::InitializationData()); auto p = Gentoo::PortagePrx::checkedCast(ic->stringToProxy("portage:tcp -p 9001")); BOOST_REQUIRE(p); auto pkgs = p->getPackagesInCategory(312); BOOST_REQUIRE_EQUAL(124, pkgs.size()); std::vector ths; auto startTime = boost::date_time::microsec_clock::universal_time(); for (int x = 0; x < THREADS; x += 1) { ths.push_back(new std::thread(&test, p, pkgs)); } sleep(10); run = false; while (!ths.empty()) { ths.back()->join(); ths.pop_back(); } auto stopTime = boost::date_time::microsec_clock::universal_time(); fprintf(stderr, "Completed %d hits in %ld sec\n", (int)count, (stopTime - startTime).total_milliseconds()); fprintf(stderr, " - %ld hits/second\n", ((count * 1000) / ((stopTime - startTime).total_milliseconds()))); ic->destroy(); }