From b46b85b22ff2a251e164361d1ca8999d2db9e972 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 30 Jun 2020 15:33:12 -0700 Subject: [PATCH 1/2] BENCH: implement asvs for get_resolution --- asv_bench/benchmarks/tslibs/resolution.py | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 asv_bench/benchmarks/tslibs/resolution.py diff --git a/asv_bench/benchmarks/tslibs/resolution.py b/asv_bench/benchmarks/tslibs/resolution.py new file mode 100644 index 0000000000000..bce13a6715058 --- /dev/null +++ b/asv_bench/benchmarks/tslibs/resolution.py @@ -0,0 +1,50 @@ +""" +ipython analogue: + +tr = TimeResolution() +mi = pd.MultiIndex.from_product(tr.params[:-1] + ([str(x) for x in tr.params[-1]],)) +df = pd.DataFrame(np.nan, index=mi, columns=["mean", "stdev"]) + +for unit in tr.params[0]: + for size in tr.params[1]: + for tz in tr.params[2]: + tr.setup_cache(unit, size, tz) + key = (unit, size, str(tz)) + print(key) + + val = %timeit -o tr.time_get_resolution(unit, size, tz) + + df.loc[key] = (val.average, val.stdev) + +""" +from datetime import timedelta, timezone + +from dateutil.tz import gettz, tzlocal +import numpy as np +import pytz + +from pandas._libs.tslibs.resolution import get_resolution + + +class TimeResolution: + params = ( + ["D", "h", "m", "s", "us", "ns"], + [1, 100, 10 ** 4, 10 ** 6], + [ + None, + timezone.utc, + timezone(timedelta(minutes=60)), + pytz.timezone("US/Pacific"), + gettz("Asia/Tokyo"), + tzlocal(), + ], + ) + param_names = ["unit", "size", "tz"] + + def setup_cache(self, unit, size, tz): + arr = np.random.randint(0, 10, size=size, dtype="i8") + arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8") + self.i8data = arr + + def time_get_resolution(self, unit, size, tz): + get_resolution(self.i8data, tz) From ee8e1dcecf6a10d455544ddb701fd86b5d8a5db4 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 30 Jun 2020 17:56:00 -0700 Subject: [PATCH 2/2] setup_cache->setup --- asv_bench/benchmarks/tslibs/resolution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asv_bench/benchmarks/tslibs/resolution.py b/asv_bench/benchmarks/tslibs/resolution.py index bce13a6715058..274aa1ad6d4a9 100644 --- a/asv_bench/benchmarks/tslibs/resolution.py +++ b/asv_bench/benchmarks/tslibs/resolution.py @@ -8,7 +8,7 @@ for unit in tr.params[0]: for size in tr.params[1]: for tz in tr.params[2]: - tr.setup_cache(unit, size, tz) + tr.setup(unit, size, tz) key = (unit, size, str(tz)) print(key) @@ -41,7 +41,7 @@ class TimeResolution: ) param_names = ["unit", "size", "tz"] - def setup_cache(self, unit, size, tz): + def setup(self, unit, size, tz): arr = np.random.randint(0, 10, size=size, dtype="i8") arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8") self.i8data = arr