-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf.py
60 lines (48 loc) · 1.07 KB
/
perf.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pytest
import numpy as np
from mapbuffer import MapBuffer, HEADER_LENGTH
import random
import time
import pickle
pf = open("pkl.tsv", "a")
mf = open("mb.tsv", "a")
def mkdataset(datasize):
return {
random.randint(0, 1000000000): np.random.bytes(random.randint(0,50000))
for _ in range(datasize)
}
def test_pkl(data):
datasize = len(data)
labels = list(data.keys())
random.shuffle(labels)
labels = labels[:datasize//10]
pkl = pickle.dumps(data)
s = time.time()
dat = pickle.loads(pkl)
for label in labels:
dat[label]
t = time.time() - s
pf.write(f"{datasize}\t{t*1000:.5f}\n")
pf.flush()
def test_mb(data):
datasize = len(data)
labels = list(data.keys())
random.shuffle(labels)
labels = labels[:datasize//10]
mbuf = MapBuffer(data)
buf = mbuf.tobytes()
s = time.time()
mbuf = MapBuffer(buf)
for label in labels:
mbuf[label]
t = time.time() - s
mf.write(f"{datasize}\t{t*1000:.5f}\n")
mf.flush()
sz = 1
while sz < 1000000:
data = mkdataset(sz)
# test_pkl(data)
test_mb(data)
sz *= 2
mf.close()
pf.close()