Commit 267c70c7 authored by neverlord's avatar neverlord

gen_server performance test

parent c3b7b23e
CXX = /opt/local/bin/g++-mp-4.6
CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -I/opt/local/include/ -I/Users/neverlord/libcppa -fpermissive -O2
LIBS = -L/opt/local/lib -lboost_thread-mt -L/Users/neverlord/libcppa/.libs/ -lcppa
all:
$(CXX) $(CXXFLAGS) $(LIBS) -o sequential_send sequential_send.cpp
$(CXX) $(CXXFLAGS) $(LIBS) -o parallel_send parallel_send.cpp
#include <iostream>
#include "cppa/cppa.hpp"
#include "cppa/to_string.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/detail/task_scheduler.hpp"
#include <boost/progress.hpp>
using std::cout;
using std::endl;
using boost::timer;
using namespace cppa;
void counter_actor()
{
long count = 0;
receive_loop
(
on<atom("Get")>() >> [&]()
{
reply(count);
count = 0;
},
on<atom("AddCount"), long>() >> [&](long val)
{
count += val;
}
);
}
constexpr long s_val = 100;
void send_range(actor_ptr counter, actor_ptr parent, int from, int to)
{
for (int i = from; i < to; ++i)
{
send(counter, atom("AddCount"), s_val);
}
send(parent, atom("Done"));
}
long the_test(int msg_count)
{
actor_ptr self_ptr = self();
auto counter = spawn(counter_actor);
for (int i = 1; i < (msg_count / 1000); ++i)
{
monitor(spawn(send_range, counter, self_ptr, (i-1)*1000, i*1000));
}
auto rule = on<atom("Done"), any_type*>() >> []() { };
for (int i = 1; i < (msg_count / 1000); ++i)
{
receive(rule);
}
send(counter, atom("Get"));
long result = 0;
receive
(
on<long>() >> [&](long value)
{
result = value;
}
);
send(counter, atom(":Exit"), exit_reason::user_defined);
return result;
}
void run_test(int msg_count)
{
timer t0;
long count = the_test(msg_count);
auto elapsed = t0.elapsed();
cout << "Count is " << count << endl
<< "Test took " << elapsed << " seconds" << endl
<< "Throughput = " << (msg_count / elapsed) << " per sec" << endl;
}
int main()
{
run_test(3000000);
return 0;
}
#include <iostream>
#include "cppa/cppa.hpp"
#include "cppa/to_string.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/detail/task_scheduler.hpp"
#include <boost/progress.hpp>
using std::cout;
using std::endl;
using boost::timer;
using namespace cppa;
void counter_actor()
{
long count = 0;
receive_loop
(
on<atom("Get")>() >> [&]()
{
reply(count);
count = 0;
},
on<atom("AddCount"), long>() >> [&](long val)
{
count += val;
}
);
}
long the_test(int msg_count)
{
constexpr long val = 100;
auto counter = spawn(counter_actor);
for (int i = 0; i < msg_count; ++i)
{
send(counter, atom("AddCount"), val);
}
send(counter, atom("Get"));
long result = 0;
receive
(
on<long>() >> [&](long value)
{
result = value;
}
);
send(counter, atom(":Exit"), exit_reason::user_defined);
return result;
}
void run_test(int msg_count)
{
timer t0;
long count = the_test(msg_count);
auto elapsed = t0.elapsed();
cout << "Count is " << count << endl
<< "Test took " << elapsed << " seconds" << endl
<< "Throughput = " << (msg_count / elapsed) << " per sec" << endl;
}
int main()
{
run_test(3000000);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment