In [5]:
import os
import subprocess
from time import time

def bench(cmd, reps=10):
    times = []
    for i in range(reps):
        s = time()
        subprocess.call(cmd)
        d = time() - s
        times.append(d)
        print('{:02d}. {:0.3f}s'.format(i + 1, d))

    av = sum(times) / float(reps)
    print('-' * 15)
    print('{:0.3f}s/run'.format(av))

In [6]:
REPS = 10
QUERY = 'quimby'

In [7]:
bench(['../src/searchio', 'search', 'google-en', QUERY], REPS)


01. 0.941s
02. 0.333s
03. 0.316s
04. 0.323s
05. 0.306s
06. 0.346s
07. 0.396s
08. 0.327s
09. 0.314s
10. 0.341s
---------------
0.394s/run

In [8]:
bench(['../src/search', 'google-en', QUERY], REPS)


01. 0.348s
02. 0.033s
03. 0.026s
04. 0.032s
05. 0.024s
06. 0.026s
07. 0.025s
08. 0.025s
09. 0.029s
10. 0.028s
---------------
0.060s/run