@@ -284,56 +284,77 @@ class timeseries_asof(object):
284
284
goal_time = 0.2
285
285
286
286
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 )
292
287
self .N = 10000
293
288
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 )
295
289
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
296
295
297
- def time_timeseries_asof (self ):
296
+ # test speed of pre-computing NAs.
297
+ def time_asof_list (self ):
298
298
self .ts .asof (self .dates )
299
299
300
+ # should be roughly the same as above.
301
+ def time_asof_nan_list (self ):
302
+ self .ts2 .asof (self .dates )
300
303
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 ])
303
308
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 ))
315
313
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 ])
318
319
319
320
320
- class timeseries_asof_single (object ):
321
+ class timeseries_dataframe_asof (object ):
321
322
goal_time = 0.2
322
323
323
324
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 )
329
325
self .N = 10000
326
+ self .M = 100
330
327
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 )
332
328
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 )
333
338
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 ):
335
346
self .ts .asof (self .dates [0 ])
336
347
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
+
337
358
338
359
class timeseries_custom_bday_apply (object ):
339
360
goal_time = 0.2
0 commit comments