Skip to content

Commit 4503c38

Browse files
committed
Added benchmarks for messages / sec.
1 parent 206b771 commit 4503c38

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

benchmark.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from maslite import Agent, Scheduler, AgentMessage
2+
3+
class Msg(AgentMessage):
4+
def __init__(self, sender, receiver=None, topic=None):
5+
super().__init__(sender, receiver, topic)
6+
self.value = 0
7+
8+
class A(Agent):
9+
def __init__(self, uuid=None):
10+
super().__init__(uuid)
11+
12+
def update(self):
13+
if self.messages:
14+
m = self.receive()
15+
assert isinstance(m, Msg)
16+
m.value += 1
17+
m.receiver, m.sender = m.sender, m.receiver
18+
self.send(m)
19+
20+
21+
if __name__ == "__main__":
22+
s = Scheduler()
23+
a = A()
24+
b = A()
25+
s.add(a)
26+
s.add(b)
27+
m = Msg(a,b)
28+
a.send(m)
29+
s.run(seconds=10)
30+
print(f"{m.value/10:,} messages/second")
31+
32+
# :~$ python3.10 benchmarks.py
33+
# 340,283.8 messages/second
34+
35+
# :-$ pypy3 benchmarks.py
36+
# 2,975,577.7 messages/second
37+

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ All right reserved © 2016-2023. MIT-license. All code has been written by t
2424
MASlite is a simle python module for creating multi-agent simulations.
2525

2626
- _Simple_ API: Only 3 modules to learn: Scheduler, Agent & Agent message
27-
- _Fast_: Handles up to 2.7 million messages per second
27+
- _Fast_: Handles up to 2.7M messages per second ([pypy, py310](./benchmark.py))
2828
- _Lightweight_: 52kB.
2929

3030
It only has 3 components:
3131

3232
- The scheduler (main loop)
3333
- handles pause and proceed with a single call.
3434
- assures repeatability in execution, which makes agents easy to debug.
35-
- handles up to 2.7 million messages per second.
35+
- handles up to 2.7M messages per second (pypy)
3636

3737
- Agent's
3838

0 commit comments

Comments
 (0)