-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_csv.py
83 lines (62 loc) · 2.46 KB
/
make_csv.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import csv
import os
import re
import sys
def make_csv(csv_file=None, bench_type="redis"):
"""Generate csv data from benchmark.md file"""
if not csv_file:
csv_file = "data.csv"
benchmark_data = parse_md(bench_type=bench_type)
with open(csv_file, 'w') as f:
writer = csv.writer(f)
if bench_type == "redis":
header = ["DB", "SET", "GET", "INCR", "LPUSH", "LPOP", "LPUSH",
"LRANGE_100", "LRANGE_300", "LRANGE_500", "LRANGE_600", "MSET"]
writer.writerow(header)
elif bench_type == "ledis":
header = ["DB", "SET", "INCR", "GET", "RPUSH", "LRANGE_10",
"LRANGE_50", "LRANGE_100", "LPOP", "HSET", "HGET",
"HINCRBY", "HDEL", "ZADD", "ZINCRBY", "ZRANGE",
"ZRANGEBYSCORE", "ZREVRANGE", "ZREVRANGEBYSCORE", "ZREM"]
writer.writerow(header)
writer.writerows(benchmark_data)
def parse_md(md_file=None, bench_type="redis"):
if not md_file:
md_file = "benchmark.md"
if not os.path.exists(md_file):
print "No markdown file found."
sys.exit()
rgl = re.compile("```(\w*?)\n(.+?)```", re.S)
with open(md_file) as f:
db_list = []
result = re.findall(rgl, f.read())
for db in result:
if len(db[0]) == 0:
continue
cmd_list = []
if db[0].split("_")[1] == bench_type:
db_type = db[0].split("_")[0]
if db_type == "goleveldb":
db_type = "ledisdb_goleveldb"
if db_type == "leveldb":
db_type = "ledisdb_leveldb"
if db_type == "rocksdb":
db_type = "ledisdb_rocksdb"
if db_type == "lmdb":
db_type = "ledisdb_lmdb"
if db_type == "boltdb":
db_type = "ledisdb_boltdb"
cmd_list.append(db_type)
_cmds = db[1].split("\n")
cmds = _cmds[:len(_cmds)-1]
for cmd in cmds:
if not cmd:
continue
value = cmd.split(":")[1].split(" ")[1]
cmd_list.append(value)
db_list.append(cmd_list)
return db_list
if __name__ == "__main__":
make_csv(csv_file="redis.csv", bench_type="redis")
make_csv(csv_file="ledis.csv", bench_type="ledis")