Skip to content

Commit 408e742

Browse files
committed
DOC: more vbench scaffolding, rst generation
1 parent 875e4f2 commit 408e742

File tree

6 files changed

+106
-44
lines changed

6 files changed

+106
-44
lines changed

doc/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,4 @@ See the package overview for more detail about what's in the library.
125125
comparison_with_r
126126
benchmarks
127127
api
128+
vbench

vb_suite/generate_rst_files.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from suite import benchmarks, generate_rst_files
2+
generate_rst_files(benchmarks)

vb_suite/groupby.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
setup = common_setup + """
88
99
N = 100000
10-
ngroups = 5
10+
ngroups = 100
1111
1212
def get_test_data(ngroups=100, n=N):
1313
unique_groups = range(ngroups)
@@ -28,12 +28,12 @@ def f():
2828
"""
2929

3030
stmt1 = "df.groupby(['key1', 'key2'])['data'].agg(lambda x: x.values.sum())"
31-
bm_groupby1 = Benchmark(stmt1, setup,
32-
name="groupby_multi_python",
33-
start_date=datetime(2011, 7, 1))
31+
groupby_multi_python = Benchmark(stmt1, setup,
32+
name="groupby_multi_python",
33+
start_date=datetime(2011, 7, 1))
3434

3535
stmt3 = "df.groupby(['key1', 'key2']).sum()"
36-
bm_groupby3 = Benchmark(stmt3, setup,
37-
name="groupby_multi_cython",
38-
start_date=datetime(2011, 7, 1))
36+
groupby_multi_cython = Benchmark(stmt3, setup,
37+
name="groupby_multi_cython",
38+
start_date=datetime(2011, 7, 1))
3939

vb_suite/index_object.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from vbench.benchmark import Benchmark
2+
from datetime import datetime
3+
4+
SECTION = "Index / MultiIndex objects"
5+

vb_suite/run_suite.py

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,12 @@
1-
from vbench.api import Benchmark, GitRepo, BenchmarkRunner
2-
from datetime import datetime
3-
4-
modules = ['groupby', 'indexing', 'reindex', 'binary_ops',
5-
'sparse', 'index_object']
6-
7-
all_benchmarks = []
8-
for modname in modules:
9-
ref = __import__(modname)
10-
for k, v in ref.__dict__.iteritems():
11-
if isinstance(v, Benchmark):
12-
all_benchmarks.append(v)
13-
14-
REPO_PATH = '/home/wesm/code/pandas'
15-
REPO_URL = '[email protected]:wesm/pandas.git'
16-
DB_PATH = '/home/wesm/code/pandas/vb_suite/benchmarks.db'
17-
TMP_DIR = '/home/wesm/tmp/vb_pandas'
18-
PREPARE = """
19-
python setup.py clean
20-
"""
21-
BUILD = """
22-
python setup.py build_ext --inplace
23-
"""
24-
dependencies = ['pandas_vb_common.py']
25-
26-
START_DATE = datetime(2011, 3, 1)
27-
28-
repo = GitRepo(REPO_PATH)
29-
30-
to_consider = repo.shas.truncate(START_DATE)
31-
32-
runner = BenchmarkRunner(all_benchmarks, REPO_PATH, REPO_URL,
33-
BUILD, DB_PATH, TMP_DIR, PREPARE,
34-
run_option='eod', start_date=START_DATE,
35-
module_dependencies=dependencies)
36-
37-
runner.run()
1+
from vbench.api import BenchmarkRunner
2+
from suite import *
3+
4+
def run_process():
5+
runner = BenchmarkRunner(benchmarks, REPO_PATH, REPO_URL,
6+
BUILD, DB_PATH, TMP_DIR, PREPARE,
7+
run_option='eod', start_date=START_DATE,
8+
module_dependencies=dependencies)
9+
runner.run()
10+
11+
if __name__ == '__main__':
12+
run_process()

vb_suite/suite.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from vbench.api import Benchmark, GitRepo, BenchmarkRunner
2+
from datetime import datetime
3+
4+
import os
5+
6+
modules = ['groupby', 'indexing', 'reindex', 'binary_ops',
7+
'sparse', 'index_object']
8+
9+
benchmarks = []
10+
for modname in modules:
11+
ref = __import__(modname)
12+
for k, v in ref.__dict__.iteritems():
13+
if isinstance(v, Benchmark):
14+
benchmarks.append(v)
15+
16+
REPO_PATH = '/home/wesm/code/pandas'
17+
REPO_URL = '[email protected]:wesm/pandas.git'
18+
DB_PATH = '/home/wesm/code/pandas/vb_suite/benchmarks.db'
19+
TMP_DIR = '/home/wesm/tmp/vb_pandas'
20+
PREPARE = """
21+
python setup.py clean
22+
"""
23+
BUILD = """
24+
python setup.py build_ext --inplace
25+
"""
26+
dependencies = ['pandas_vb_common.py']
27+
28+
START_DATE = datetime(2011, 3, 1)
29+
30+
repo = GitRepo(REPO_PATH)
31+
32+
RST_BASE = '../doc/source'
33+
34+
# HACK!
35+
36+
timespan = [datetime(2011, 1, 1), datetime(2012, 1, 1)]
37+
38+
def generate_rst_files(benchmarks):
39+
import matplotlib as mpl
40+
mpl.use('Agg')
41+
import matplotlib.pyplot as plt
42+
43+
vb_path = os.path.join(RST_BASE, 'vbench')
44+
fig_base_path = os.path.join(vb_path, 'figures')
45+
46+
if not os.path.exists(vb_path):
47+
print 'creating %s' % vb_path
48+
os.makedirs(vb_path)
49+
50+
if not os.path.exists(fig_base_path):
51+
print 'creating %s' % fig_base_path
52+
os.makedirs(fig_base_path)
53+
54+
for bmk in benchmarks:
55+
print 'Generating rst file for %s' % bmk.name
56+
rst_path = os.path.join(RST_BASE, 'vbench/%s.rst' % bmk.name)
57+
58+
fig_full_path = os.path.join(fig_base_path, '%s.png' % bmk.name)
59+
60+
# make the figure
61+
plt.figure(figsize=(10, 6))
62+
ax = plt.gca()
63+
bmk.plot(DB_PATH, ax=ax)
64+
plt.xlim(timespan)
65+
plt.savefig(fig_full_path, bbox_inches='tight')
66+
plt.close('all')
67+
68+
fig_rel_path = 'vbench/figures/%s.png' % bmk.name
69+
rst_text = bmk.to_rst(image_path=fig_rel_path)
70+
with open(rst_path, 'w') as f:
71+
f.write(rst_text)
72+
73+
with open(os.path.join(RST_BASE, 'vbench.rst'), 'w') as f:
74+
print >> f, """
75+
VBENCH
76+
------
77+
"""
78+
for bmk in benchmarks:
79+
print >> f, '.. include:: vbench/%s.rst' % bmk.name

0 commit comments

Comments
 (0)