Commit f05f95d6 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[scripts] Cleanup using black

parent 356f6ff4
......@@ -12,18 +12,16 @@ import time
import zmq
prefix = pkg_resources.resource_filename(__name__, '../test/prefix')
prefix = pkg_resources.resource_filename(__name__, "../test/prefix")
print(prefix)
class CustomDataSource(DataSource):
def __init__(self, nb_data_units, dataformat):
self.nb_data_units = nb_data_units
self.current = 0
self.dataformat = dataformat
self.file = open('benchmark.data', 'rb')
self.file = open("benchmark.data", "rb")
self.unpack = True
def next(self):
......@@ -50,20 +48,20 @@ class CustomDataSource(DataSource):
def main():
dataformat = DataFormat(prefix, 'user/empty_1d_array_of_integers/1')
dataformat = DataFormat(prefix, "user/empty_1d_array_of_integers/1")
data = dataformat.type(value=np.random.randint(100000, size=(1000000,), dtype=np.int32))
data = dataformat.type(
value=np.random.randint(100000, size=(1000000,), dtype=np.int32)
)
with open('benchmark.data', 'wb') as f:
with open("benchmark.data", "wb") as f:
f.write(data.pack())
#-----------------------
# -----------------------
data_source = CustomDataSource(10000, dataformat)
print('Nb Data units: %d' % data_source.nb_data_units)
print("Nb Data units: %d" % data_source.nb_data_units)
t1 = time.time()
......@@ -72,12 +70,14 @@ def main():
t2 = time.time()
print('Datasource (unpack): %.3fs (%.3fms/unit)' % (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units))
print(
"Datasource (unpack): %.3fs (%.3fms/unit)"
% (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units)
)
data_source.reset()
#-----------------------
# -----------------------
data_source.unpack = False
......@@ -88,16 +88,16 @@ def main():
t2 = time.time()
print('Datasource (packed): %.3fs (%.3fms/unit)' % (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units))
print(
"Datasource (packed): %.3fs (%.3fms/unit)"
% (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units)
)
data_source.reset()
# -----------------------
#-----------------------
input = Input('a', 'user/empty_1d_array_of_integers/1', data_source)
input = Input("a", "user/empty_1d_array_of_integers/1", data_source)
t1 = time.time()
......@@ -106,13 +106,14 @@ def main():
t2 = time.time()
print('Input (unpack): %.3fs (%.3fms/unit)' % (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units))
print(
"Input (unpack): %.3fs (%.3fms/unit)"
% (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units)
)
data_source.reset()
#-----------------------
# -----------------------
data_source.unpack = False
......@@ -123,37 +124,36 @@ def main():
t2 = time.time()
print('Input (packed): %.3fs (%.3fms/unit)' % (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units))
print(
"Input (packed): %.3fs (%.3fms/unit)"
% (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units)
)
data_source.reset()
# -----------------------
#-----------------------
group = InputGroup('channel')
group = InputGroup("channel")
group.add(input)
input_list = InputList()
input_list.add(group)
server_context = zmq.Context()
server_socket = server_context.socket(zmq.PAIR)
address = 'tcp://127.0.0.1'
address = "tcp://127.0.0.1"
port = server_socket.bind_to_random_port(address)
address += ':%d' % port
address += ":%d" % port
message_handler = MessageHandler(input_list, server_context, server_socket)
client_context = zmq.Context()
client_socket = client_context.socket(zmq.PAIR)
client_socket.connect(address)
remote_input = RemoteInput('a', dataformat, client_socket)
remote_input = RemoteInput("a", dataformat, client_socket)
remote_group = InputGroup('channel', restricted_access=False)
remote_group = InputGroup("channel", restricted_access=False)
remote_group.add(remote_input)
remote_input_list = InputList()
......@@ -161,7 +161,6 @@ def main():
message_handler.start()
t1 = time.time()
while remote_input.hasMoreData():
......@@ -169,12 +168,14 @@ def main():
t2 = time.time()
print('Remote (unpack): %.3fs (%.3fms/unit)' % (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units))
print(
"Remote (unpack): %.3fs (%.3fms/unit)"
% (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units)
)
data_source.reset()
#-----------------------
# -----------------------
data_source.unpack = False
# message_handler.unpack = False
......@@ -186,6 +187,9 @@ def main():
t2 = time.time()
print('Remote (packed): %.3fs (%.3fms/unit)' % (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units))
print(
"Remote (packed): %.3fs (%.3fms/unit)"
% (t2 - t1, (t2 - t1) * 1000.0 / data_source.nb_data_units)
)
data_source.reset()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment