Datasets:
File size: 1,700 Bytes
faa3682 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import pathlib
import sys
import time
sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
import elements
import zerofun
import numpy as np
class TestBandwidth:
def test_numpy_read(self):
arr = np.ones((128, 1024, 1024), np.int64) # 1 GiB
size = arr.nbytes / (1024 ** 3)
for _ in range(10):
with elements.timer.section('step'):
arr.sum()
dt = elements.timer.stats()['step/avg']
print(f'numpy_read: {dt:.3f} avg | {size / dt:.2f} gib/s')
def test_numpy_copy(self):
arr = np.ones((1024, 1024, 1024), np.uint8)
size = arr.nbytes / (1024 ** 3)
for _ in range(10):
with elements.timer.section('step'):
arr.copy()
dt = elements.timer.stats()['step/avg']
print(f'numpy_copy: {dt:.3f} avg | {size / dt:.2f} gib/s')
def test_socket_send(self):
shape, dtype, gib = (1024, 1024, 1024), np.uint8, 1.00
def server(context, addr):
server = zerofun.Server(addr)
data = {'foo': np.ones(shape, dtype)}
server.bind('function', lambda _: data)
with server:
while context.running:
time.sleep(0.01)
addr = f'tcp://localhost:{zerofun.get_free_port()}'
proc = zerofun.StoppableProcess(server, addr, start=True)
client = zerofun.Client(addr)
client.connect()
for _ in range(10):
with elements.timer.section('step'):
client.function({}).result()
proc.stop()
dt = elements.timer.stats()['step/avg']
print(f'socket_send: {dt:.3f} avg | {gib / dt:.2f} gib/s')
if __name__ == '__main__':
TestBandwidth().test_numpy_read() # 21 gib/s
TestBandwidth().test_numpy_copy() # 7 gib/s
TestBandwidth().test_socket_send() # 4 gib/s
|