Skip to content

Commit

Permalink
Added benchmarks for messages / sec.
Browse files Browse the repository at this point in the history
  • Loading branch information
root-11 committed Jan 31, 2024
1 parent 206b771 commit 4503c38
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from maslite import Agent, Scheduler, AgentMessage

class Msg(AgentMessage):
def __init__(self, sender, receiver=None, topic=None):
super().__init__(sender, receiver, topic)
self.value = 0

class A(Agent):
def __init__(self, uuid=None):
super().__init__(uuid)

def update(self):
if self.messages:
m = self.receive()
assert isinstance(m, Msg)
m.value += 1
m.receiver, m.sender = m.sender, m.receiver
self.send(m)


if __name__ == "__main__":
s = Scheduler()
a = A()
b = A()
s.add(a)
s.add(b)
m = Msg(a,b)
a.send(m)
s.run(seconds=10)
print(f"{m.value/10:,} messages/second")

# :~$ python3.10 benchmarks.py
# 340,283.8 messages/second

# :-$ pypy3 benchmarks.py
# 2,975,577.7 messages/second

4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ All right reserved © 2016-2023. MIT-license. All code has been written by t
MASlite is a simle python module for creating multi-agent simulations.

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

It only has 3 components:

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

- Agent's

Expand Down

0 comments on commit 4503c38

Please sign in to comment.