Advertisement
mrmamongo

redis benches

May 5th, 2023
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import asyncio
  2. import time
  3.  
  4. import numpy as np
  5. import redis.asyncio as redis
  6.  
  7.  
  8. async def bench_gather(number: int):
  9.     rd = redis.Redis(port=9998)
  10.  
  11.     async def create_value(key: str, value: bytes):
  12.         start = time.monotonic()
  13.         await rd.set(key, value)
  14.         return time.monotonic() - start
  15.  
  16.     results = []
  17.     for i in range(number):
  18.         results.append(await create_value(f"test_{i}", b"test_value"))
  19.     return results
  20.  
  21.  
  22. np.set_printoptions(suppress=True, precision=16)
  23. results = np.array(asyncio.run(bench_gather(10000)))
  24. print("Max write time")
  25. print(f"{results.max():.16f}")
  26.  
  27. print("Min write time")
  28. print(f"{results.min():.16f}")
  29.  
  30. print("Avg write time")
  31. print(f"{results.mean():.16f}")
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement