Skip to content

Commit

Permalink
Refactor asv tests for Series.asof. Add asv tests for DataFrame.asof
Browse files Browse the repository at this point in the history
  • Loading branch information
laudney committed Oct 25, 2016
1 parent a920f8f commit 9190a96
Showing 1 changed file with 51 additions and 30 deletions.
81 changes: 51 additions & 30 deletions asv_bench/benchmarks/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,56 +284,77 @@ class timeseries_asof(object):
goal_time = 0.2

def setup(self):
self.N = 100000
self.rng = date_range(start='1/1/2000', periods=self.N, freq='T')
if hasattr(Series, 'convert'):
Series.resample = Series.convert
self.ts = Series(np.random.randn(self.N), index=self.rng)
self.N = 10000
self.rng = date_range(start='1/1/1990', periods=self.N, freq='53s')
self.ts = Series(np.random.randn(self.N), index=self.rng)
self.dates = date_range(start='1/1/1990', periods=(self.N * 10), freq='5s')
self.ts = Series(np.random.randn(self.N), index=self.rng)
self.ts2 = self.ts.copy()
self.ts2[250:5000] = np.nan
self.ts3 = self.ts.copy()
self.ts3[-5000:] = np.nan

def time_timeseries_asof(self):
# test speed of pre-computing NAs.
def time_asof_list(self):
self.ts.asof(self.dates)

# should be roughly the same as above.
def time_asof_nan_list(self):
self.ts2.asof(self.dates)

class timeseries_asof_nan(object):
goal_time = 0.2
# test speed of the code path for a scalar index
# without *while* loop
def time_asof_single(self):
self.ts.asof(self.dates[0])

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

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


class timeseries_asof_single(object):
class timeseries_dataframe_asof(object):
goal_time = 0.2

def setup(self):
self.N = 100000
self.rng = date_range(start='1/1/2000', periods=self.N, freq='T')
if hasattr(Series, 'convert'):
Series.resample = Series.convert
self.ts = Series(np.random.randn(self.N), index=self.rng)
self.N = 10000
self.M = 100
self.rng = date_range(start='1/1/1990', periods=self.N, freq='53s')
self.ts = Series(np.random.randn(self.N), index=self.rng)
self.dates = date_range(start='1/1/1990', periods=(self.N * 10), freq='5s')
self.ts = DataFrame(np.random.randn(self.N * self.M).reshape((self.N, self.M)), index=self.rng)
self.ts2 = self.ts.copy()
self.ts2.iloc[250:5000] = np.nan
self.ts3 = self.ts.copy()
self.ts3.iloc[-5000:] = np.nan

# test speed of pre-computing NAs.
def time_asof_list(self):
self.ts.asof(self.dates)

def time_timeseries_asof_single(self):
# should be roughly the same as above.
def time_asof_nan_list(self):
self.ts2.asof(self.dates)

# test speed of the code path for a scalar index
# with pre-computing all NAs.
def time_asof_single(self):
self.ts.asof(self.dates[0])

# should be roughly the same as above.
def time_asof_nan_single(self):
self.ts3.asof(self.dates[-1])

# test speed of the code path for a scalar index
# before the start. should be without the cost of
# pre-computing all the NAs.
def time_asof_single_early(self):
self.ts.asof(self.dates[0] - dt.timedelta(10))


class timeseries_custom_bday_apply(object):
goal_time = 0.2
Expand Down

0 comments on commit 9190a96

Please sign in to comment.