Skip to content

Instantly share code, notes, and snippets.

@atdt
Created July 2, 2014 00:02
Show Gist options
  • Save atdt/1a401372a2306cf666f0 to your computer and use it in GitHub Desktop.
Save atdt/1a401372a2306cf666f0 to your computer and use it in GitHub Desktop.
from statistics import median, mean
import time
import re
import requests
import subprocess
warmups = 15
trials = 15
hosts = ('osmium', 'mw1020')
headers = {'host': 'en.wikivoyage.org'}
def toggle_jit(enable=True):
target = str(enable).lower()
subprocess.call('/bin/sed -i"" -e"s/Jit = .*/Jit = %s/" /etc/hhvm/config.hdf' % target, shell=True)
subprocess.call('/sbin/restart hhvm >/dev/null 2>&1', shell=True)
with open('/var/run/hhvm/hhvm.hhbc.sq3', 'wb'):
pass # truncate file
time.sleep(2)
print('{:<15}{:<15}{:<15}{:<15}{:<15}'.format('', 'mean', 'median', 'min', 'max'))
def bench(host, jit=None):
caption = host
if jit is not None:
caption += '(%sjit)' % ('+' if jit else '-')
toggle_jit(jit)
results = []
for i in range(0, warmups + trials):
start = time.time()
req = requests.get('http://%s/wiki/Main_Page' % host, headers=headers)
resp_time = int(re.search(r'wgBackendResponseTime":(\d+),', req.text).groups(0)[0])
results.append(resp_time)
req.raise_for_status()
results = results[warmups:]
print('{:<15}{:<15.2f}{:<15.2f}{:<15.2f}{:<15.2f}'.format(caption, mean(results), median(results), min(results), max(results)))
bench('mw1020')
bench('osmium', False)
bench('osmium', True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment