def setUp(self): self.ms = MockServer() self.run = patch('hurraypy.client.Connection._run', side_effect=self.ms.run) self.connect = patch('hurraypy.client.Connection._connect', side_effect=_connect) self.run_mock = self.run.start() self.connect_mock = self.connect.start() self.conn = hp.connect('host', 'port')
def main(): repetitions = 3 engines = ("hurray", "hurray_uds", "h5py", "h5pyswmr") results = {"bigdata": {}, "smalldata": {}} for test_case in ("bigdata", "smalldata"): for engine in engines: conn = None if engine == "hurray": conn = hrr.connect("localhost", "2222") elif engine == "hurray_uds": conn = hrr.connect(unix_socket_path="/tmp/hurray.socket") def timer_function(function, *args): def wrap(): function(*args) t = timeit.Timer(wrap) return t.timeit(repetitions) results[test_case][engine] = timer_function( test, engine, test_case, conn) for test_case, result in results.items(): print("\ntest case '{}'".format(test_case)) print("#####################\n") print("Total running time for {} repetitions:".format(repetitions)) for engine in engines: sec = results[test_case][engine] print("{}:{}{:.2f}s".format(engine, " " * (11 - len(engine)), sec)) secs_hurray = results[test_case]["hurray"] secs_hurray_uds = results[test_case]["hurray_uds"] print("⇒ h5py was ~{:.0f} times faster than hurray over TCP".format( secs_hurray / results[test_case]["h5py"])) print("⇒ h5py was ~{:.0f} times faster than hurray over UDS".format( secs_hurray_uds / results[test_case]["h5py"])) print( "⇒ h5pyswmr was ~{:.0f} times faster than hurray over TCP".format( secs_hurray / results[test_case]["h5pyswmr"])) print( "⇒ h5pyswmr was ~{:.0f} times faster than hurray over UDS".format( secs_hurray_uds / results[test_case]["h5pyswmr"]))
def _test_socket(self): conn = hp.connect(unix_socket_path='/tmp/hurray.socket') self.operations(conn)
def test_tcp(self): conn = hp.connect('localhost', '2222') self.operations(conn)
import logging import hurraypy as hr logger = logging.getLogger('hurraypy') console = logging.StreamHandler() console.setLevel(logging.DEBUG) console.setFormatter(logging.Formatter('%(levelname)s --- %(message)s')) logger.addHandler(console) logger.setLevel(logging.DEBUG) conn = hr.connect('localhost', '2222') f2 = conn.create_file("test_asdf.h5", overwrite=True) f2.delete() # f2 = conn.create_file("test_asdf.h5", overwrite=True) conn.close()