summaryrefslogtreecommitdiff
path: root/docs/client_examples/run_benchmark.py
blob: ddedf433e6e9530022368406c308b2d5a0164b7c (plain)
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
"""
Run a mini-benchmark between regular api and dbapi
"""
import commands
import os
import time

TMPDIR = os.environ.get("TMPDIR", "/tmp")
CSVFILE = 'bench.csv'

cmd = "SILENT=1 TIMES={times} TMPDIR={tmpdir} python ./use_{version}api.py"


def parse_time(r):
    return r.split('\n')[-1]


with open(CSVFILE, 'w') as log:

    for times in range(0, 10000, 500):
        cmd1 = cmd.format(times=times, tmpdir=TMPDIR, version="")
        sync_time = parse_time(commands.getoutput(cmd1))

        cmd2 = cmd.format(times=times, tmpdir=TMPDIR, version="adb")
        async_time = parse_time(commands.getoutput(cmd2))

        print times, sync_time, async_time
        log.write("%s, %s, %s\n" % (times, sync_time, async_time))
        log.flush()
        time.sleep(2)