-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
49 lines (43 loc) · 1.18 KB
/
client.py
File metadata and controls
49 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import yaml
from n_cache import NCache
from pprint import pprint
import random
from time import time
class bcolors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
domainSize = 6
sampleSize = 20
def main():
config = []
with open("config.yml") as fp:
config = yaml.safe_load(fp)
cache = NCache(config)
data = "abcdefghijklmnopqrstuvwxyz"[:min(domainSize, 26)]
for _ in range(sampleSize):
k, v = random.choice(data), random.choice(data)
if random.randint(0, 10) < 7:
st = time()
cache.write(k, v)
print(
bcolors.OKBLUE
+ "write: {}={}, time taken: {:.2}".format(k, v, time() - st)
+ bcolors.ENDC
)
else:
st = time()
v = cache.read(k)
color = bcolors.OKGREEN if v else bcolors.FAIL
print(
color
+ "read: {}={}, time taken: {:.2}".format(k, v, time() - st)
+ bcolors.ENDC
)
if __name__ == "__main__":
main()