Skip to content

Commit 9190a96

Browse files
committed
Refactor asv tests for Series.asof. Add asv tests for DataFrame.asof
1 parent a920f8f commit 9190a96

File tree

1 file changed

+51
-30
lines changed

1 file changed

+51
-30
lines changed

asv_bench/benchmarks/timeseries.py

+51-30
Original file line numberDiff line numberDiff line change
@@ -284,56 +284,77 @@ class timeseries_asof(object):
284284
goal_time = 0.2
285285

286286
def setup(self):
287-
self.N = 100000
288-
self.rng = date_range(start='1/1/2000', periods=self.N, freq='T')
289-
if hasattr(Series, 'convert'):
290-
Series.resample = Series.convert
291-
self.ts = Series(np.random.randn(self.N), index=self.rng)
292287
self.N = 10000
293288
self.rng = date_range(start='1/1/1990', periods=self.N, freq='53s')
294-
self.ts = Series(np.random.randn(self.N), index=self.rng)
295289
self.dates = date_range(start='1/1/1990', periods=(self.N * 10), freq='5s')
290+
self.ts = Series(np.random.randn(self.N), index=self.rng)
291+
self.ts2 = self.ts.copy()
292+
self.ts2[250:5000] = np.nan
293+
self.ts3 = self.ts.copy()
294+
self.ts3[-5000:] = np.nan
296295

297-
def time_timeseries_asof(self):
296+
# test speed of pre-computing NAs.
297+
def time_asof_list(self):
298298
self.ts.asof(self.dates)
299299

300+
# should be roughly the same as above.
301+
def time_asof_nan_list(self):
302+
self.ts2.asof(self.dates)
300303

301-
class timeseries_asof_nan(object):
302-
goal_time = 0.2
304+
# test speed of the code path for a scalar index
305+
# without *while* loop
306+
def time_asof_single(self):
307+
self.ts.asof(self.dates[0])
303308

304-
def setup(self):
305-
self.N = 100000
306-
self.rng = date_range(start='1/1/2000', periods=self.N, freq='T')
307-
if hasattr(Series, 'convert'):
308-
Series.resample = Series.convert
309-
self.ts = Series(np.random.randn(self.N), index=self.rng)
310-
self.N = 10000
311-
self.rng = date_range(start='1/1/1990', periods=self.N, freq='53s')
312-
self.ts = Series(np.random.randn(self.N), index=self.rng)
313-
self.dates = date_range(start='1/1/1990', periods=(self.N * 10), freq='5s')
314-
self.ts[250:5000] = np.nan
309+
# test speed of the code path for a scalar index
310+
# before the start. should be the same as above.
311+
def time_asof_single_early(self):
312+
self.ts.asof(self.dates[0] - dt.timedelta(10))
315313

316-
def time_timeseries_asof_nan(self):
317-
self.ts.asof(self.dates)
314+
# test the speed of the code path for a scalar index
315+
# with a long *while* loop. should still be much
316+
# faster than pre-computing all the NAs.
317+
def time_asof_nan_single(self):
318+
self.ts3.asof(self.dates[-1])
318319

319320

320-
class timeseries_asof_single(object):
321+
class timeseries_dataframe_asof(object):
321322
goal_time = 0.2
322323

323324
def setup(self):
324-
self.N = 100000
325-
self.rng = date_range(start='1/1/2000', periods=self.N, freq='T')
326-
if hasattr(Series, 'convert'):
327-
Series.resample = Series.convert
328-
self.ts = Series(np.random.randn(self.N), index=self.rng)
329325
self.N = 10000
326+
self.M = 100
330327
self.rng = date_range(start='1/1/1990', periods=self.N, freq='53s')
331-
self.ts = Series(np.random.randn(self.N), index=self.rng)
332328
self.dates = date_range(start='1/1/1990', periods=(self.N * 10), freq='5s')
329+
self.ts = DataFrame(np.random.randn(self.N * self.M).reshape((self.N, self.M)), index=self.rng)
330+
self.ts2 = self.ts.copy()
331+
self.ts2.iloc[250:5000] = np.nan
332+
self.ts3 = self.ts.copy()
333+
self.ts3.iloc[-5000:] = np.nan
334+
335+
# test speed of pre-computing NAs.
336+
def time_asof_list(self):
337+
self.ts.asof(self.dates)
333338

334-
def time_timeseries_asof_single(self):
339+
# should be roughly the same as above.
340+
def time_asof_nan_list(self):
341+
self.ts2.asof(self.dates)
342+
343+
# test speed of the code path for a scalar index
344+
# with pre-computing all NAs.
345+
def time_asof_single(self):
335346
self.ts.asof(self.dates[0])
336347

348+
# should be roughly the same as above.
349+
def time_asof_nan_single(self):
350+
self.ts3.asof(self.dates[-1])
351+
352+
# test speed of the code path for a scalar index
353+
# before the start. should be without the cost of
354+
# pre-computing all the NAs.
355+
def time_asof_single_early(self):
356+
self.ts.asof(self.dates[0] - dt.timedelta(10))
357+
337358

338359
class timeseries_custom_bday_apply(object):
339360
goal_time = 0.2

0 commit comments

Comments
 (0)