Skip to content

Commit

Permalink
Another perf test
Browse files Browse the repository at this point in the history
Signed-off-by: James Noss <[email protected]>
  • Loading branch information
jamienoss committed Dec 3, 2021
1 parent 7ecc110 commit f39ad0f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
12 changes: 6 additions & 6 deletions catkit/testbed/tests/test_shared_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ def test_Mbps(reset_HicatTestbedState, shape, limit):
t_get = [0]*n

for i in range(n):
t0 = time.time()
t0 = time.perf_counter_ns()
shared_state.m = data
t1 = time.time()
t_set[i] = t1 - t0
t1 = time.perf_counter_ns()
t_set[i] = (t1 - t0)*1e-9

t0 = time.time()
t0 = time.perf_counter_ns()
_resp = shared_state.m
t1 = time.time()
t_get[i] = t1 - t0
t1 = time.perf_counter_ns()
t_get[i] = (t1 - t0)*1e-9

print(f"{i}: {n_Mb/t_set[i]:.2f}Mbps {n_Mb/t_get[i]:.2f}Mbps")
mean_get_mbps = n_Mb/np.mean(t_get)
Expand Down
68 changes: 68 additions & 0 deletions catkit/tests/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,71 @@ def test_instrument_property():
obj = manager.InstrumentWithProperty(config_id="npoint_tiptilt_lc_400", com_id="dummy", timeout=TIMEOUT)
assert isinstance(obj, BaseProxy)
assert obj.position == "this is a property"



from catkit.interfaces.Instrument import Instrument
import copy
import numpy as np
import sys


class DummyInst(Instrument):
instrument_lib = None

def initialize(self, *args, **kwargs):
self.data = None

def _open(self):
return self

def _close(self):
pass

def set_data(self, data, n_bytes, do_copy):
self.data = copy.deepcopy(data) if do_copy else data
assert sys.getsizeof(self.data) == n_bytes

def get_data(self):
return self.data


SharedMemoryManager.register("DummyInst", callable=DummyInst, proxytype=DummyInst.Proxy, create_method=True)


# shape, limit = (712, 712), 50 # Image.
# shape, limit = ((34, 34, 2)), 900 # Double Boston Dm command.
@pytest.mark.parametrize(("shape", "limit"), (((712, 712), 50), ((34, 34, 2), 900)))
def test_Mbps(shape, limit):
with SharedMemoryManager(address=("127.0.0.1", 6060)) as manager:
n = 100
dtype = np.float64
data = np.zeros(shape, dtype=dtype)
n_B = sys.getsizeof(data)
n_Mb = n_B*8/1e6

t_set = [0]*n
t_get = [0]*n

with manager.DummyInst("dummy") as dev:
for i in range(n):
t0 = time.perf_counter_ns()
dev.set_data(data, n_B, True)
t1 = time.perf_counter_ns()
t_set[i] = (t1 - t0)*1e-9

t0 = time.perf_counter_ns()
_resp = dev.get_data()
t1 = time.perf_counter_ns()
t_get[i] = (t1 - t0)*1e-9

print(f"{i}: {n_Mb/t_set[i]:.2f}Mbps {n_Mb/t_get[i]:.2f}Mbps")

mean_get_mbps = n_Mb/np.mean(t_get)
mean_set_mbps = n_Mb/np.mean(t_set)
mean_rate = 1/np.mean(t_get)

print(f"Mean perf: GET: {mean_get_mbps:.2f}Mbps, SET: {mean_set_mbps:.2f}Mbps")
print(f"Mean rate for image transfer of {shape} ({dtype}): {mean_rate:.2f}Hz")
assert mean_rate > limit
# assert False

0 comments on commit f39ad0f

Please sign in to comment.