Skip to content

Commit

Permalink
performance testing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Dec 13, 2020
1 parent 349cf1c commit 28fe975
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/performance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Performance
===========

This directory contains several scripts and tools to test the performance of
the project.
19 changes: 19 additions & 0 deletions tests/performance/binary_b64_packet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time
from engineio import packet


def test():
p = packet.Packet(packet.MESSAGE, b'hello world')
start = time.time()
count = 0
while True:
p = packet.Packet(encoded_packet=p.encode(b64=True))
count += 1
if time.time() - start >= 5:
break
return count


if __name__ == '__main__':
count = test()
print('binary_b64_packet:', count, 'packets processed.')
19 changes: 19 additions & 0 deletions tests/performance/binary_packet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time
from engineio import packet


def test():
p = packet.Packet(packet.MESSAGE, b'hello world')
start = time.time()
count = 0
while True:
p = packet.Packet(encoded_packet=p.encode())
count += 1
if time.time() - start >= 5:
break
return count


if __name__ == '__main__':
count = test()
print('binary_packet:', count, 'packets processed.')
19 changes: 19 additions & 0 deletions tests/performance/json_packet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time
from engineio import packet


def test():
p = packet.Packet(packet.MESSAGE, {'hello': 'world'})
start = time.time()
count = 0
while True:
p = packet.Packet(encoded_packet=p.encode())
count += 1
if time.time() - start >= 5:
break
return count


if __name__ == '__main__':
count = test()
print('json_packet:', count, 'packets processed.')
20 changes: 20 additions & 0 deletions tests/performance/payload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import time
from engineio import packet, payload


def test():
p = payload.Payload(
packets=[packet.Packet(packet.MESSAGE, b'hello world')] * 10)
start = time.time()
count = 0
while True:
p = payload.Payload(encoded_payload=p.encode())
count += 1
if time.time() - start >= 5:
break
return count


if __name__ == '__main__':
count = test()
print('payload:', count, 'payloads processed.')
7 changes: 7 additions & 0 deletions tests/performance/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
python text_packet.py
python binary_packet.py
python binary_b64_packet.py
python json_packet.py
python payload.py
python server_receive.py
37 changes: 37 additions & 0 deletions tests/performance/server_receive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import io
import sys
import time
import engineio


def test(eio_version, payload):
s = engineio.Server()
start = time.time()
count = 0
s.handle_request({
'REQUEST_METHOD': 'GET',
'QUERY_STRING': eio_version,
}, lambda s, h: None)
sid = list(s.sockets.keys())[0]
while True:
environ = {
'REQUEST_METHOD': 'POST',
'QUERY_STRING': eio_version + '&sid=' + sid,
'CONTENT_LENGTH': '6',
'wsgi.input': io.BytesIO(payload)
}
s.handle_request(environ, lambda s, h: None)
count += 1
if time.time() - start >= 5:
break
return count


if __name__ == '__main__':
eio_version = 'EIO=4'
payload = b'4hello'
if len(sys.argv) > 1 and sys.argv[1] == '3':
eio_version = 'EIO=3'
payload = b'\x00\x06\xff4hello'
count = test(eio_version, payload)
print('server_receive:', count, 'packets received.')
19 changes: 19 additions & 0 deletions tests/performance/text_packet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import time
from engineio import packet


def test():
p = packet.Packet(packet.MESSAGE, 'hello world')
start = time.time()
count = 0
while True:
p = packet.Packet(encoded_packet=p.encode())
count += 1
if time.time() - start >= 5:
break
return count


if __name__ == '__main__':
count = test()
print('text_packet:', count, 'packets processed.')

0 comments on commit 28fe975

Please sign in to comment.