Skip to content

Commit e74e012

Browse files
authored
TEST-#2705: add 'value_counts' benchmarks (#2706)
* TEST-#2705: add 'value_counts' benchmarks Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com> * TEST-#2705: apply suggestions from review Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
1 parent b93b879 commit e74e012

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

asv_bench/benchmarks/benchmarks.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,49 @@ def time_fillna(self, shape, limit, inplace):
441441
execute(self.df)
442442
else:
443443
execute(self.df.fillna(**kw))
444+
445+
446+
class BaseTimeValueCounts:
447+
subset_params = {
448+
"all": lambda shape: shape[1],
449+
"half": lambda shape: shape[1] // 2,
450+
}
451+
452+
def setup(self, shape, subset="all"):
453+
try:
454+
subset = self.subset_params[subset]
455+
except KeyError:
456+
raise KeyError(
457+
f"Invalid value for 'subset={subset}'. Allowed: {list(self.subset_params.keys())}"
458+
)
459+
ncols = subset(shape)
460+
self.df, _ = generate_dataframe(
461+
ASV_USE_IMPL,
462+
"int",
463+
*shape,
464+
RAND_LOW,
465+
RAND_HIGH,
466+
groupby_ncols=ncols,
467+
count_groups=GROUPBY_NGROUPS[ASV_DATASET_SIZE],
468+
)
469+
self.subset = self.df.columns[:ncols].tolist()
470+
471+
472+
class TimeValueCountsFrame(BaseTimeValueCounts):
473+
param_names = ["shape", "subset"]
474+
params = [UNARY_OP_DATA_SIZE[ASV_DATASET_SIZE], ["all", "half"]]
475+
476+
def time_value_counts(self, *args, **kwargs):
477+
execute(self.df.value_counts(subset=self.subset))
478+
479+
480+
class TimeValueCountsSeries(BaseTimeValueCounts):
481+
param_names = ["shape", "bins"]
482+
params = [UNARY_OP_DATA_SIZE[ASV_DATASET_SIZE], [None, 3]]
483+
484+
def setup(self, shape, bins):
485+
super().setup(shape=shape)
486+
self.df = self.df.iloc[:, 0]
487+
488+
def time_value_counts(self, shape, bins):
489+
execute(self.df.value_counts(bins=bins))

0 commit comments

Comments
 (0)