def timit(func):
async def wrapper():
begin = time.time()
await func()
stop = time.time()
print(f"total time of {func.__name__}: {stop - begin}")
return wrapper
@timit
async def natspy_main_nonconcurrent() :
client = NATS()
await client.connect('downtimer-nats1:4222')
for _ in range(1_000_0):
await client.publish("some", b"1")
await client.close()
@timit
async def natsrpy_main_nonconcurrent() :
client = Nats(
addrs=['downtimer-nats1:4222']
)
await client.startup()
for _ in range(1_000_0):
await client.publish("some", b"1")
await client.shutdown()
total time of natspy_main_nonconcurrent: 0.02205514907836914
total time of natsrpy_main_nonconcurrent: 2.494574546813965
Did some benchmarks
Code example:
Output:
Additional details: