Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
b0f79b3a
Commit
b0f79b3a
authored
Jan 06, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
benchmark update
parent
fcb7d04f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
254 additions
and
0 deletions
+254
-0
benchmarks/MailboxPerformance.scala
benchmarks/MailboxPerformance.scala
+80
-0
benchmarks/mailbox_performance.cpp
benchmarks/mailbox_performance.cpp
+144
-0
benchmarks/mailbox_performance.erl
benchmarks/mailbox_performance.erl
+30
-0
No files found.
benchmarks/MailboxPerformance.scala
0 → 100644
View file @
b0f79b3a
import
scala.actors.Actor
import
scala.actors.Actor._
import
akka.actor.Actor.actorOf
import
scala.annotation.tailrec
case
object
Msg
object
global
{
val
latch
=
new
java
.
util
.
concurrent
.
CountDownLatch
(
1
)
}
class
ThreadedReceiver
(
n
:
Long
)
extends
Actor
{
def
act
()
{
var
i
:
Long
=
0
while
(
i
<
n
)
receive
{
case
Msg
=>
i
+=
1
}
Console
println
"received "
+
i
+
" messages"
}
}
class
ThreadlessReceiver
(
n
:
Long
)
extends
Actor
{
def
rcv
(
rest
:
Long
)
{
react
{
case
Msg
=>
if
(
rest
>
0
)
rcv
(
rest
-
1
);
}
}
def
act
()
{
rcv
(
n
);
}
}
class
AkkaReceiver
(
n
:
Long
)
extends
akka
.
actor
.
Actor
{
var
received
:
Long
=
0
def
receive
=
{
case
Msg
=>
received
+=
1
if
(
received
==
n
)
{
global
.
latch
.
countDown
self
.
exit
}
}
}
object
MailboxPerformance
{
def
usage
()
{
Console
println
"usage: (threaded|threadless|akka) (num_threads) (msgs_per_thread)"
}
def
cr_threads
(
receiver
:
{
def
!
(
msg:Any
)
:
Unit
},
threads
:
Int
,
msgs
:
Int
)
{
for
(
i
<-
0
until
threads
)
(
new
java
.
lang
.
Thread
{
override
def
run
()
{
for
(
j
<-
0
until
msgs
)
receiver
!
Msg
}
}).
start
}
def
main
(
args
:
Array
[
String
])
=
{
if
(
args
.
size
!=
3
)
{
usage
throw
new
IllegalArgumentException
(
""
)
}
val
threads
=
args
(
1
).
toInt
val
msgs
=
args
(
2
).
toInt
if
(
args
(
0
)
==
"threaded"
)
{
cr_threads
((
new
ThreadedReceiver
(
threads
*
msgs
)).
start
,
threads
,
msgs
)
}
else
if
(
args
(
0
)
==
"threadless"
)
{
cr_threads
((
new
ThreadlessReceiver
(
threads
*
msgs
)).
start
,
threads
,
msgs
)
}
else
if
(
args
(
0
)
==
"akka"
)
{
val
a
=
actorOf
(
new
AkkaReceiver
(
threads
*
msgs
)).
start
// akka actors define operator! with implicit argument
cr_threads
(
new
AnyRef
{
def
!
(
what
:
Any
)
{
a
!
what
}
},
threads
,
msgs
)
global
.
latch
.
await
}
else
usage
}
}
benchmarks/mailbox_performance.cpp
0 → 100644
View file @
b0f79b3a
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \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/>. *
\******************************************************************************/
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "cppa/cppa.hpp"
#include "cppa/fsm_actor.hpp"
using
std
::
cout
;
using
std
::
cerr
;
using
std
::
endl
;
using
std
::
int64_t
;
using
namespace
cppa
;
struct
fsm_receiver
:
fsm_actor
<
fsm_receiver
>
{
int64_t
m_value
;
behavior
init_state
;
fsm_receiver
(
int64_t
max
)
:
m_value
(
0
)
{
init_state
=
(
on
(
atom
(
"msg"
))
>>
[
=
]()
{
++
m_value
;
if
(
m_value
==
max
)
{
quit
(
exit_reason
::
normal
);
}
}
);
}
};
void
receiver
(
int64_t
max
)
{
int64_t
value
;
receive_loop
(
on
(
atom
(
"msg"
))
>>
[
&
]()
{
++
value
;
if
(
value
==
max
)
{
std
::
cout
<<
"received "
<<
value
<<
" messages"
<<
endl
;
quit
(
exit_reason
::
normal
);
}
}
);
}
void
sender
(
actor_ptr
whom
,
int64_t
count
)
{
any_tuple
msg
=
make_tuple
(
atom
(
"msg"
));
for
(
int64_t
i
=
0
;
i
<
count
;
++
i
)
{
whom
->
enqueue
(
nullptr
,
msg
);
}
}
void
usage
()
{
cout
<<
"usage: mailbox_performance "
"(stacked|event-based) (sending threads) (msg per thread)"
<<
endl
<<
endl
;
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
==
4
)
{
char
*
endptr
=
nullptr
;
int64_t
num_sender
=
static_cast
<
int64_t
>
(
strtol
(
argv
[
2
],
&
endptr
,
10
));
if
(
endptr
==
nullptr
||
*
endptr
!=
'\0'
)
{
cerr
<<
"
\"
"
<<
argv
[
2
]
<<
"
\"
is not an integer"
<<
endl
;
usage
();
return
1
;
}
int64_t
num_msgs
=
static_cast
<
int64_t
>
(
strtol
(
argv
[
3
],
&
endptr
,
10
));
if
(
endptr
==
nullptr
||
*
endptr
!=
'\0'
)
{
cerr
<<
"
\"
"
<<
argv
[
3
]
<<
"
\"
is not an integer"
<<
endl
;
usage
();
return
1
;
}
actor_ptr
testee
;
if
(
strcmp
(
argv
[
1
],
"stacked"
)
==
0
)
{
testee
=
spawn
(
receiver
,
num_sender
*
num_msgs
);
}
else
if
(
strcmp
(
argv
[
1
],
"event-based"
)
==
0
)
{
testee
=
spawn
(
new
fsm_receiver
(
num_sender
*
num_msgs
));
}
else
{
usage
();
return
1
;
}
for
(
int64_t
i
=
0
;
i
<
num_sender
;
++
i
)
{
spawn
<
detached
>
(
sender
,
testee
,
num_msgs
);
}
await_all_others_done
();
}
else
{
usage
();
return
1
;
}
return
0
;
}
benchmarks/mailbox_performance.erl
0 → 100644
View file @
b0f79b3a
-
module
(
mailbox_performance
).
-
export
([
start
/
1
,
sender
/
2
]).
sender
(_,
0
)
->
0
;
sender
(
Pid
,
Num
)
->
Pid
!
{
msg
},
sender
(
Pid
,
Num
-
1
).
start_senders
(_,
_,
0
)
->
0
;
start_senders
(
Pid
,
Arg
,
Num
)
->
spawn
(
mailbox_performance
,
sender
,
[
Pid
,
Arg
]),
start_senders
(
Pid
,
Arg
,
Num
-
1
).
receive_messages
(
0
)
->
0
;
receive_messages
(
Num
)
->
receive
{
msg
}
->
receive_messages
(
Num
-
1
)
end
.
start
(
Args
)
->
[
H1
|
T
]
=
Args
,
NumSender
=
list_to_integer
(
atom_to_list
(
H1
)),
[
H2
|_]
=
T
,
NumMsgs
=
list_to_integer
(
atom_to_list
(
H2
)),
start_senders
(
self
(),
NumMsgs
,
NumSender
),
receive_messages
(
NumMsgs
*
NumSender
).
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment