-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.py
executable file
·37 lines (28 loc) · 988 Bytes
/
bench.py
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
#!/usr/bin/env python
from datetime import timedelta
import random
import string
from timeit import Timer
from pathlib import Path
from tempfile import TemporaryDirectory
from expiringsqlitedict import SqliteDict
population = string.ascii_letters + string.digits + string.punctuation
with TemporaryDirectory() as dir:
db_file = Path(dir) / 'test.db'
def test():
with SqliteDict(str(db_file), lifespan=timedelta(seconds=1)) as db:
k = ''.join(random.choices(population, k=10))
v = ''.join(random.choices(population, k=10))
db[k] = v
timer = Timer('test()', globals={'test': test})
runs = 0
time = 0
# Run for at least 5 seconds
for second in range(5):
for fraction in range(5):
part_runs, part_time = timer.autorange()
runs += part_runs
time += part_time
size = db_file.stat().st_size
print(f'{runs=} / {time=} = {runs / time=}')
print(f'{size=}')