Skip to content

Commit 2ef6a30

Browse files
committed
PERF: add asv benchmarks for crosstab()
1 parent 9176c36 commit 2ef6a30

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

asv_bench/benchmarks/reshape.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,30 @@ def time_pivot_table_margins(self):
140140
margins=True)
141141

142142

143+
class Crosstab(object):
144+
145+
def setup(self):
146+
N = 100000
147+
fac1 = np.array(['A', 'B', 'C'], dtype='O')
148+
fac2 = np.array(['one', 'two'], dtype='O')
149+
self.ind1 = np.random.randint(0, 3, size=N)
150+
self.ind2 = np.random.randint(0, 2, size=N)
151+
self.vec1 = fac1.take(self.ind1)
152+
self.vec2 = fac2.take(self.ind2)
153+
154+
def time_crosstab(self):
155+
pd.crosstab(self.vec1, self.vec2)
156+
157+
def time_crosstab_values(self):
158+
pd.crosstab(self.vec1, self.vec2, values=self.ind1, aggfunc='sum')
159+
160+
def time_crosstab_normalize(self):
161+
pd.crosstab(self.vec1, self.vec2, normalize=True)
162+
163+
def time_crosstab_normalize_margins(self):
164+
pd.crosstab(self.vec1, self.vec2, normalize=True, margins=True)
165+
166+
143167
class GetDummies(object):
144168
def setup(self):
145169
categories = list(string.ascii_letters[:12])

0 commit comments

Comments
 (0)