Commit b33b7052 authored by neverlord's avatar neverlord

benchmark update

parent 508ab179
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include "utility.hpp"
#include "cppa/cppa.hpp" #include "cppa/cppa.hpp"
#include "cppa/fsm_actor.hpp" #include "cppa/fsm_actor.hpp"
...@@ -117,23 +118,6 @@ void usage() ...@@ -117,23 +118,6 @@ void usage()
<< endl; << endl;
} }
template<typename T>
T rd(char const* cstr)
{
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
std::string errstr;
errstr += "\"";
errstr += cstr;
errstr += "\" is not an integer";
usage();
throw std::invalid_argument(errstr);
}
return result;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc == 3) if (argc == 3)
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include "utility.hpp"
#include "cppa/cppa.hpp" #include "cppa/cppa.hpp"
#include "cppa/fsm_actor.hpp" #include "cppa/fsm_actor.hpp"
#include "cppa/detail/thread.hpp" #include "cppa/detail/thread.hpp"
...@@ -92,23 +93,6 @@ void usage() ...@@ -92,23 +93,6 @@ void usage()
<< endl; << endl;
} }
template<typename T>
T rd(char const* cstr)
{
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
std::string errstr;
errstr += "\"";
errstr += cstr;
errstr += "\" is not an integer";
usage();
throw std::invalid_argument(errstr);
}
return result;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc == 4) if (argc == 4)
......
-module(matching).
-export([start/1]).
partFun(msg1, X) when X =:= 0 -> true;
partFun(msg2, 0.0) -> true;
partFun(msg3, [0|[]]) -> true.
partFun(msg4, 0, "0") -> true.
partFun(msg5, A, B, C) when A =:= 0; B =:= 0; C =:= 0 -> true;
partFun(msg6, A, 0.0, "0") when A =:= 0 -> true.
loop(0) -> true;
loop(N) ->
partFun(msg1, 0),
partFun(msg2, 0.0),
partFun(msg3, [0]),
partFun(msg4, 0, "0"),
partFun(msg5, 0, 0, 0),
partFun(msg6, 0, 0.0, "0"),
loop(N-1).
start(X) ->
[H|[]] = X,
N = list_to_integer(atom_to_list(H)),
loop(N).
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include "utility.hpp"
#include "cppa/cppa.hpp" #include "cppa/cppa.hpp"
#include "cppa/fsm_actor.hpp" #include "cppa/fsm_actor.hpp"
...@@ -315,23 +316,6 @@ void usage() ...@@ -315,23 +316,6 @@ void usage()
<< endl; << endl;
} }
template<typename T>
T rd(char const* cstr)
{
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
std::string errstr;
errstr += "\"";
errstr += cstr;
errstr += "\" is not an integer";
usage();
throw std::invalid_argument(errstr);
}
return result;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
announce<factors>(); announce<factors>();
......
#define THERON_USE_BOOST_THREADS 1
#include <Theron/Framework.h>
#include <Theron/Actor.h>
#include <thread>
#include <cstdint>
#include <iostream>
#include <functional>
#include "utility.hpp"
using std::cerr;
using std::cout;
using std::endl;
using std::int64_t;
using std::uint32_t;
using namespace Theron;
struct spread { int value; };
struct result { uint32_t value; };
THERON_REGISTER_MESSAGE(spread);
THERON_REGISTER_MESSAGE(result);
template<typename RefType>
struct testee_base : Actor;
struct testee : testee_base<RefType>
{
typedef struct { Address arg0; } Parameters;
Address m_parent;
bool m_first_result_received;
uint32_t m_first_result;
std::vector<RefType> m_children;
void spread_handler(spread const& arg, const Address)
{
if (arg.value == 0)
{
Send(result{1}, m_parent);
}
else
{
spread msg = {arg.value-1};
Parameters params = {GetAddress()};
for (int i = 0; i < 2; ++i)
{
m_children.push_back(GetFramework().CreateActor<testee<RefType>>(params));
m_children.back().Push(msg, GetAddress());
}
}
}
void result_handler(result const& arg, const Address)
{
if (!m_first_result_received)
{
m_first_result_received = true;
m_first_result = arg.value;
}
else
{
Send(result{m_first_result + arg.value});
m_children.clear();
}
}
send_testee(Parameters const& p) : m_parent(p.arg0), m_first_result_received(false)
{
RegisterHandler(this, &send_testee::spread_handler);
RegisterHandler(this, &send_testee::result_handler);
}
};
void usage()
{
cout << "usage: theron_actor_creation _ POW" << endl
<< " creates 2^POW actors" << endl
<< endl;
}
int main(int argc, char** argv)
{
if (argc != 3)
{
usage();
return 1;
}
int num = rd<int>(argv[2]);
Receiver r;
Framework framework;
ActorRef aref(framework.CreateActor<testee>(teste::Parameters{r.GetAddress()}));
aref.Push(spread{num}, r.GetAddress());
r.Wait();
}
#define THERON_USE_BOOST_THREADS 1 #define THERON_USE_BOOST_THREADS 1
#include <Theron/Framework.h>
#include <Theron/Framework.h> #include <Theron/Actor.h>
#include <Theron/Actor.h>
#include <thread> #include <thread>
#include <cstdint> #include <cstdint>
#include <iostream> #include <iostream>
#include <functional> #include <functional>
#include "utility.hpp"
using std::cerr; using std::cerr;
using std::cout; using std::cout;
using std::endl; using std::endl;
...@@ -17,89 +18,68 @@ using namespace Theron; ...@@ -17,89 +18,68 @@ using namespace Theron;
int64_t t_max = 0; int64_t t_max = 0;
// A trivial actor that does nothing. struct receiver : Actor
struct receiver : Actor
{ {
int64_t m_num; int64_t m_num;
void handler(int64_t const&, Address from) void handler(int64_t const&, const Address from)
{ {
if (++m_num == t_max) if (++m_num == t_max)
Send(t_max, from); Send(t_max, from);
} }
//receiver(int64_t max, Address waiter) : m_max(max), m_num(0), m_waiter(waiter)
receiver() : m_num(0) receiver() : m_num(0)
{ {
RegisterHandler(this, &receiver::handler); RegisterHandler(this, &receiver::handler);
} }
}; };
void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num)
{ {
auto addr = ref.GetAddress(); auto addr = ref.GetAddress();
int64_t msg; int64_t msg;
for (int64_t i = 0; i < num; ++i) for (int64_t i = 0; i < num; ++i) f.Send(msg, waiter, addr);
f.Send(msg, waiter, addr);
//ref.Push(msg, ref.GetAddress());
} }
void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num)
{ {
int64_t msg; int64_t msg;
for (int64_t i = 0; i < num; ++i) for (int64_t i = 0; i < num; ++i) ref.Push(msg, waiter);
ref.Push(msg, waiter);
}
template<typename T>
T rd(char const* cstr)
{
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
std::string errstr;
errstr += "\"";
errstr += cstr;
errstr += "\" is not an integer";
throw std::invalid_argument(errstr);
}
return result;
} }
void usage() void usage()
{ {
cout << "usage ('push'|'send') (num_threads) (num_messages)" << endl; cout << "usage ('push'|'send') (num_threads) (num_messages)" << endl;
exit(1); exit(1);
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc != 4) if (argc != 4)
{ {
return 1; return 1;
} }
enum { invalid_impl, push_impl, send_impl } impl = invalid_impl; enum { invalid_impl, push_impl, send_impl } impl = invalid_impl;
if (strcmp(argv[1], "push") == 0) impl = push_impl; if (strcmp(argv[1], "push") == 0) impl = push_impl;
else if (strcmp(argv[1], "send") == 0) impl = send_impl; else if (strcmp(argv[1], "send") == 0) impl = send_impl;
else usage(); else usage();
auto num_sender = rd<int64_t>(argv[2]); auto num_sender = rd<int64_t>(argv[2]);
auto num_msgs = rd<int64_t>(argv[3]); auto num_msgs = rd<int64_t>(argv[3]);
Receiver r; Receiver r;
t_max = num_sender * num_msgs; t_max = num_sender * num_msgs;
auto receiverAddr = r.GetAddress(); auto receiverAddr = r.GetAddress();
Framework framework; Framework framework;
ActorRef aref(framework.CreateActor<receiver>()); ActorRef aref(framework.CreateActor<receiver>());
std::list<std::thread> threads; std::list<std::thread> threads;
auto impl_fun = (impl == push_impl) ? send_sender : push_sender; auto impl_fun = (impl == push_impl) ? send_sender : push_sender;
for (int64_t i = 0; i < num_sender; ++i) for (int64_t i = 0; i < num_sender; ++i)
{ {
threads.push_back(std::thread(impl_fun, std::ref(framework), aref, receiverAddr, num_msgs)); threads.push_back(std::thread(impl_fun, std::ref(framework), aref, receiverAddr, num_msgs));
} }
r.Wait(); r.Wait();
for (auto& t : threads) t.join(); for (auto& t : threads) t.join();
return 0; return 0;
} }
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef UTILITY_HPP
#define UTILITY_HPP
#include <stdexcept>
template<typename T>
T rd(char const* cstr)
{
char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0')
{
std::string errstr;
errstr += "\"";
errstr += cstr;
errstr += "\" is not an integer";
throw std::invalid_argument(errstr);
}
return result;
}
#endif // UTILITY_HPP
...@@ -254,3 +254,7 @@ cppa/any_tuple_view.hpp ...@@ -254,3 +254,7 @@ cppa/any_tuple_view.hpp
cppa/match.hpp cppa/match.hpp
benchmarks/Matching.scala benchmarks/Matching.scala
benchmarks/matching.cpp benchmarks/matching.cpp
benchmarks/matching.erl
benchmarks/theron_mailbox_performance.cpp
benchmarks/utility.hpp
benchmarks/theron_actor_creation.cpp
...@@ -153,7 +153,6 @@ class is_pm_decorated ...@@ -153,7 +153,6 @@ class is_pm_decorated
}; };
template<class TupleIterator, class PatternIterator> template<class TupleIterator, class PatternIterator>
//int matches(TupleIterator targ, typename pattern<P...>::const_iterator iter)
auto matches(TupleIterator targ, PatternIterator iter) auto matches(TupleIterator targ, PatternIterator iter)
-> typename util::enable_if_c<is_pm_decorated<TupleIterator>::value,bool>::type -> typename util::enable_if_c<is_pm_decorated<TupleIterator>::value,bool>::type
{ {
......
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