Skip to content

BENCH: programmatically create benchmarks for large ngroups (GH6787) #8410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ Performance
- Performance and memory usage improvements in multi-key ``groupby`` (:issue:`8128`)
- Performance improvements in groupby ``.agg`` and ``.apply`` where builtins max/min were not mapped to numpy/cythonized versions (:issue:`7722`)
- Performance improvement in writing to sql (``to_sql``) of up to 50% (:issue:`8208`).
- Performance benchmarking of groupby for large value of ngroups (:issue:`6787`)



Expand Down
75 changes: 75 additions & 0 deletions vb_suite/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,78 @@ def f(g):

groupby_agg_builtins1 = Benchmark("df.groupby('jim').agg([sum, min, max])", setup)
groupby_agg_builtins2 = Benchmark("df.groupby(['jim', 'joe']).agg([sum, min, max])", setup)

#----------------------------------------------------------------------
# groupby with a variable value for ngroups


ngroups_list = [100, 10000]
no_arg_func_list = [
'all',
'any',
'count',
'cumcount',
'cummax',
'cummin',
'cumprod',
'cumsum',
'describe',
'diff',
'first',
'head',
'last',
'mad',
'max',
'mean',
'median',
'min',
'nunique',
'pct_change',
'prod',
'rank',
'sem',
'size',
'skew',
'std',
'sum',
'tail',
'unique',
'var',
'value_counts',
]


_stmt_template = "df.groupby('value')['timestamp'].%s"
_setup_template = common_setup + """
np.random.seed(1234)
ngroups = %s
size = ngroups * 10
rng = np.arange(ngroups)
df = DataFrame(dict(
timestamp=rng.take(np.random.randint(0, ngroups, size=size)),
value=np.random.randint(0, size, size=size)
))
"""
START_DATE = datetime(2011, 7, 1)


def make_large_ngroups_bmark(ngroups, func_name, func_args=''):
bmark_name = 'groupby_ngroups_%s_%s' % (ngroups, func_name)
stmt = _stmt_template % ('%s(%s)' % (func_name, func_args))
setup = _setup_template % ngroups
bmark = Benchmark(stmt, setup, start_date=START_DATE)
# MUST set name
bmark.name = bmark_name
return bmark


def inject_bmark_into_globals(bmark):
if not bmark.name:
raise AssertionError('benchmark must have a name')
globals()[bmark.name] = bmark


for ngroups in ngroups_list:
for func_name in no_arg_func_list:
bmark = make_large_ngroups_bmark(ngroups, func_name)
inject_bmark_into_globals(bmark)