Skip to content

Commit c44a063

Browse files
mroeschkejreback
authored andcommitted
CLN: ASV eval benchmark (#18500)
1 parent 38f41e6 commit c44a063

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

asv_bench/benchmarks/eval.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .pandas_vb_common import *
1+
import numpy as np
22
import pandas as pd
33
try:
44
import pandas.core.computation.expressions as expr
@@ -7,64 +7,61 @@
77

88

99
class Eval(object):
10+
1011
goal_time = 0.2
1112

1213
params = [['numexpr', 'python'], [1, 'all']]
1314
param_names = ['engine', 'threads']
1415

1516
def setup(self, engine, threads):
16-
self.df = DataFrame(np.random.randn(20000, 100))
17-
self.df2 = DataFrame(np.random.randn(20000, 100))
18-
self.df3 = DataFrame(np.random.randn(20000, 100))
19-
self.df4 = DataFrame(np.random.randn(20000, 100))
17+
np.random.seed(1234)
18+
self.df = pd.DataFrame(np.random.randn(20000, 100))
19+
self.df2 = pd.DataFrame(np.random.randn(20000, 100))
20+
self.df3 = pd.DataFrame(np.random.randn(20000, 100))
21+
self.df4 = pd.DataFrame(np.random.randn(20000, 100))
2022

2123
if threads == 1:
2224
expr.set_numexpr_threads(1)
2325

2426
def time_add(self, engine, threads):
25-
df, df2, df3, df4 = self.df, self.df2, self.df3, self.df4
26-
pd.eval('df + df2 + df3 + df4', engine=engine)
27+
pd.eval('self.df + self.df2 + self.df3 + self.df4', engine=engine)
2728

2829
def time_and(self, engine, threads):
29-
df, df2, df3, df4 = self.df, self.df2, self.df3, self.df4
30-
pd.eval('(df > 0) & (df2 > 0) & (df3 > 0) & (df4 > 0)', engine=engine)
30+
pd.eval('(self.df > 0) & (self.df2 > 0) & '
31+
'(self.df3 > 0) & (self.df4 > 0)', engine=engine)
3132

3233
def time_chained_cmp(self, engine, threads):
33-
df, df2, df3, df4 = self.df, self.df2, self.df3, self.df4
34-
pd.eval('df < df2 < df3 < df4', engine=engine)
34+
pd.eval('self.df < self.df2 < self.df3 < self.df4', engine=engine)
3535

3636
def time_mult(self, engine, threads):
37-
df, df2, df3, df4 = self.df, self.df2, self.df3, self.df4
38-
pd.eval('df * df2 * df3 * df4', engine=engine)
37+
pd.eval('self.df * self.df2 * self.df3 * self.df4', engine=engine)
3938

4039
def teardown(self, engine, threads):
4140
expr.set_numexpr_threads()
4241

4342

4443
class Query(object):
44+
4545
goal_time = 0.2
4646

4747
def setup(self):
48-
self.N = 1000000
49-
self.halfway = ((self.N // 2) - 1)
50-
self.index = date_range('20010101', periods=self.N, freq='T')
51-
self.s = Series(self.index)
48+
np.random.seed(1234)
49+
self.N = 10**6
50+
self.halfway = (self.N // 2) - 1
51+
self.index = pd.date_range('20010101', periods=self.N, freq='T')
52+
self.s = pd.Series(self.index)
5253
self.ts = self.s.iloc[self.halfway]
53-
self.df = DataFrame({'a': np.random.randn(self.N), }, index=self.index)
54-
self.df2 = DataFrame({'dates': self.s.values,})
55-
56-
self.df3 = DataFrame({'a': np.random.randn(self.N),})
57-
self.min_val = self.df3['a'].min()
58-
self.max_val = self.df3['a'].max()
54+
self.df = pd.DataFrame({'a': np.random.randn(self.N), 'dates': self.s},
55+
index=self.index)
56+
self.data = np.random.randn(self.N)
57+
self.min_val = self.data.min()
58+
self.max_val = self.data.max()
5959

6060
def time_query_datetime_index(self):
61-
ts = self.ts
62-
self.df.query('index < @ts')
61+
self.df.query('index < @self.ts')
6362

64-
def time_query_datetime_series(self):
65-
ts = self.ts
66-
self.df2.query('dates < @ts')
63+
def time_query_datetime_column(self):
64+
self.df.query('dates < @self.ts')
6765

6866
def time_query_with_boolean_selection(self):
69-
min_val, max_val = self.min_val, self.max_val
70-
self.df.query('(a >= @min_val) & (a <= @max_val)')
67+
self.df.query('(a >= @self.min_val) & (a <= @self.max_val)')

0 commit comments

Comments
 (0)