diff --git a/asv_bench/benchmarks/period.py b/asv_bench/benchmarks/period.py index df3c2bf3e4b46..15d7655293ea3 100644 --- a/asv_bench/benchmarks/period.py +++ b/asv_bench/benchmarks/period.py @@ -3,141 +3,128 @@ class PeriodProperties(object): - def setup(self): - self.per = Period('2012-06-01', freq='M') + params = ['M', 'min'] + param_names = ['freq'] + + def setup(self, freq): + self.per = Period('2012-06-01', freq=freq) - def time_year(self): + def time_year(self, freq): self.per.year - def time_month(self): + def time_month(self, freq): self.per.month - def time_quarter(self): - self.per.quarter - - def time_day(self): + def time_day(self, freq): self.per.day - def time_hour(self): + def time_hour(self, freq): self.per.hour - def time_minute(self): - self.per.second + def time_minute(self, freq): + self.per.minute - def time_second(self): + def time_second(self, freq): self.per.second - def time_leap_year(self): - self.per.is_leapyear - - -class Constructor(object): - goal_time = 0.2 - - def setup(self): - self.rng = date_range('1985', periods=1000) - self.rng2 = date_range('1985', periods=1000).to_pydatetime() - - def time_from_date_range(self): - PeriodIndex(self.rng, freq='D') - - def time_from_pydatetime(self): - PeriodIndex(self.rng2, freq='D') + def time_is_leap_year(self, freq): + self.per.is_leap_year + def time_quarter(self, freq): + self.per.quarter -class DataFrame(object): - goal_time = 0.2 + def time_qyear(self, freq): + self.per.qyear - def setup(self): - self.rng = pd.period_range(start='1/1/1990', freq='S', periods=20000) - self.df = pd.DataFrame(index=range(len(self.rng))) + def time_week(self, freq): + self.per.week - def time_setitem_period_column(self): - self.df['col'] = self.rng + def time_daysinmonth(self, freq): + self.per.daysinmonth + def time_dayofweek(self, freq): + self.per.dayofweek -class Algorithms(object): - goal_time = 0.2 + def time_dayofyear(self, freq): + self.per.dayofyear - def setup(self): - data = [Period('2011-01', freq='M'), Period('2011-02', freq='M'), - Period('2011-03', freq='M'), Period('2011-04', freq='M')] - self.s = Series(data * 1000) - self.i = PeriodIndex(data, freq='M') + def time_start_time(self, freq): + self.per.start_time - def time_drop_duplicates_pseries(self): - self.s.drop_duplicates() + def time_end_time(self, freq): + self.per.end_time - def time_drop_duplicates_pindex(self): - self.i.drop_duplicates() - def time_value_counts_pseries(self): - self.s.value_counts() +class PeriodUnaryMethods(object): + params = ['M', 'min'] + param_names = ['freq'] - def time_value_counts_pindex(self): - self.i.value_counts() + def setup(self, freq): + self.per = Period('2012-06-01', freq=freq) + def time_to_timestamp(self, freq): + self.per.to_timestamp() -class Properties(object): - def setup(self): - self.per = Period('2017-09-06 08:28', freq='min') + def time_now(self, freq): + self.per.now(freq) - def time_year(self): - self.per.year + def time_asfreq(self, freq): + self.per.asfreq('A') - def time_month(self): - self.per.month - def time_day(self): - self.per.day +class PeriodIndexConstructor(object): + goal_time = 0.2 - def time_hour(self): - self.per.hour + params = ['D'] + param_names = ['freq'] - def time_minute(self): - self.per.minute + def setup(self, freq): + self.rng = date_range('1985', periods=1000) + self.rng2 = date_range('1985', periods=1000).to_pydatetime() - def time_second(self): - self.per.second + def time_from_date_range(self, freq): + PeriodIndex(self.rng, freq=freq) - def time_is_leap_year(self): - self.per.is_leap_year + def time_from_pydatetime(self, freq): + PeriodIndex(self.rng2, freq=freq) - def time_quarter(self): - self.per.quarter - def time_qyear(self): - self.per.qyear +class DataFramePeriodColumn(object): + goal_time = 0.2 - def time_week(self): - self.per.week + def setup_cache(self): + rng = pd.period_range(start='1/1/1990', freq='S', periods=20000) + df = pd.DataFrame(index=range(len(rng))) + return rng, df - def time_daysinmonth(self): - self.per.daysinmonth + def time_setitem_period_column(self, tup): + rng, df = tup + df['col'] = rng - def time_dayofweek(self): - self.per.dayofweek - def time_dayofyear(self): - self.per.dayofyear +class Algorithms(object): + goal_time = 0.2 - def time_start_time(self): - self.per.start_time + params = ['index', 'series'] + param_names = ['typ'] - def time_end_time(self): - self.per.end_time + def setup(self, typ): + data = [Period('2011-01', freq='M'), Period('2011-02', freq='M'), + Period('2011-03', freq='M'), Period('2011-04', freq='M')] - def time_to_timestamp(): - self.per.to_timestamp() + if typ == 'index': + self.vector = PeriodIndex(data * 1000, freq='M') + elif typ == 'series': + self.vector = Series(data * 1000) - def time_now(): - self.per.now() + def time_drop_duplicates(self, typ): + self.vector.drop_duplicates() - def time_asfreq(): - self.per.asfreq('A') + def time_value_counts(self, typ): + self.vector.value_counts() -class period_standard_indexing(object): +class Indexing(object): goal_time = 0.2 def setup(self): diff --git a/asv_bench/benchmarks/timedelta.py b/asv_bench/benchmarks/timedelta.py index 0f8c8458628b1..2d1ff3a24f787 100644 --- a/asv_bench/benchmarks/timedelta.py +++ b/asv_bench/benchmarks/timedelta.py @@ -31,14 +31,14 @@ def time_convert_ignore(self): to_timedelta(self.arr4, errors='ignore') -class Ops(object): +class TimedeltaOps(object): goal_time = 0.2 def setup(self): self.td = to_timedelta(np.arange(1000000)) self.ts = Timestamp('2000') - def test_add_td_ts(self): + def time_add_td_ts(self): self.td + self.ts diff --git a/asv_bench/benchmarks/timestamp.py b/asv_bench/benchmarks/timestamp.py index e8cb4c9d1c75b..b8ef309e6a464 100644 --- a/asv_bench/benchmarks/timestamp.py +++ b/asv_bench/benchmarks/timestamp.py @@ -7,8 +7,11 @@ class TimestampProperties(object): goal_time = 0.2 - def setup(self): - self.ts = Timestamp('2017-08-25 08:16:14') + params = [None, pytz.timezone('Europe/Amsterdam')] + param_names = ['tz'] + + def setup(self, tz): + self.ts = Timestamp('2017-08-25 08:16:14', tzinfo=tz) def time_tz(self): self.ts.tz @@ -65,25 +68,29 @@ def time_microsecond(self): class TimestampOps(object): goal_time = 0.2 - def setup(self): - self.ts = Timestamp('2017-08-25 08:16:14') - self.ts_tz = Timestamp('2017-08-25 08:16:14', tz='US/Eastern') + params = [None, 'US/Eastern'] + param_names = ['tz'] - dt = datetime.datetime(2016, 3, 27, 1) - self.tzinfo = pytz.timezone('CET').localize(dt, is_dst=False).tzinfo - self.ts2 = Timestamp(dt) + def setup(self, tz): + self.ts = Timestamp('2017-08-25 08:16:14', tz=tz) def time_replace_tz(self): self.ts.replace(tzinfo=pytz.timezone('US/Eastern')) - def time_replace_across_dst(self): - self.ts2.replace(tzinfo=self.tzinfo) - def time_replace_None(self): - self.ts_tz.replace(tzinfo=None) + self.ts.replace(tzinfo=None) def time_to_pydatetime(self): self.ts.to_pydatetime() - def time_to_pydatetime_tz(self): - self.ts_tz.to_pydatetime() + +class TimestampAcrossDst(object): + goal_time = 0.2 + + def setup(self): + dt = datetime.datetime(2016, 3, 27, 1) + self.tzinfo = pytz.timezone('CET').localize(dt, is_dst=False).tzinfo + self.ts2 = Timestamp(dt) + + def time_replace_across_dst(self): + self.ts2.replace(tzinfo=self.tzinfo)