Skip to content

BENCH: implement asvs for ints_to_pydatetime #35091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 2, 2020
55 changes: 55 additions & 0 deletions asv_bench/benchmarks/tslibs/tslib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
ipython analogue:

tr = TimeIntsToPydatetime()
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 box in tr.params[0]:
for size in tr.params[1]:
for tz in tr.params[2]:
tr.setup(box, size, tz)
key = (box, size, str(tz))
print(key)
val = %timeit -o tr.time_ints_to_pydatetime(box, 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.tslib import ints_to_pydatetime

_tzs = [
None,
timezone.utc,
timezone(timedelta(minutes=60)),
pytz.timezone("US/Pacific"),
gettz("Asia/Tokyo"),
tzlocal(),
]
_sizes = [0, 1, 100, 10 ** 4, 10 ** 6]


class TimeIntsToPydatetime:
params = (
["time", "date", "datetime", "timestamp"],
_sizes,
_tzs,
)
param_names = ["box", "size", "tz"]
# TODO: fold? freq?

def setup(self, box, size, tz):
arr = np.random.randint(0, 10, size=size, dtype="i8")
self.i8data = arr

def time_ints_to_pydatetime(self, box, size, tz):
if box == "date":
# ints_to_pydatetime does not allow non-None tz with date;
# this will mean doing some duplicate benchmarks
tz = None
ints_to_pydatetime(self.i8data, tz, box=box)