-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.py
58 lines (45 loc) · 1.88 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import hashlib
import sqlite3
import codecs
import argparse
import logging
import sys
args = 0
def bench():
conn = sqlite3.connect(args.db)
c = conn.cursor()
start = datetime.now()
c.execute("SELECT * FROM bench")
logging.info("Time after query: %sµs"% ((datetime.now()-start).microseconds))
i = 0
logging.info("Beginning loop")
loop_begin = datetime.now()
for row in c.fetchall():
if row[0] == 0:
d = datetime.now()
logging.info(u"Accessing first result set\n\tID: %d\n\trand: %s\n\thash: %s\ntook %d.%06d s" % (row[0], row[1], row[2], (d-loop_begin).seconds,(d-loop_begin).microseconds))
m = hashlib.sha256()
v = codecs.decode(row[1], 'hex_codec')
m.update(v)
d = m.hexdigest()
if d != row[2]:
logging.error("ID: %d" % row[0])
logging.error("Original value: %s" % r[1])
logging.error("Hash: %s" % r[2])
logging.error("Calculated hex digest: %s" % d)
raise Exception("Hashes do not match")
i += 1
end = datetime.now()
f = (end-loop_begin).seconds*1000000.0+(end-loop_begin).microseconds
logging.info ("Finished loop after %s.%06ds"% ((end-loop_begin).seconds,(end-loop_begin).microseconds))
logging.info (u"Average: %5.3fµs per record, %s overall" %((f/i),end-start))
if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s %(message)s',datefmt='%m/%d/%Y %H:%M:%S',level=logging.DEBUG,handlers=[logging.StreamHandler(sys.stdout)])
logging.info("Starting up")
parser = argparse.ArgumentParser(description='Process database entries generated by sqlite3perf')
parser.add_argument('-d','--db', nargs=1,metavar='/path/to/db',default='./sqlite3perf.db',help='database to use')
args = parser.parse_args()
bench()