Skip to content

Commit cac4bfe

Browse files
authored
BENCH: implement asvs for get_resolution (#35075)
1 parent c23228c commit cac4bfe

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
ipython analogue:
3+
4+
tr = TimeResolution()
5+
mi = pd.MultiIndex.from_product(tr.params[:-1] + ([str(x) for x in tr.params[-1]],))
6+
df = pd.DataFrame(np.nan, index=mi, columns=["mean", "stdev"])
7+
8+
for unit in tr.params[0]:
9+
for size in tr.params[1]:
10+
for tz in tr.params[2]:
11+
tr.setup(unit, size, tz)
12+
key = (unit, size, str(tz))
13+
print(key)
14+
15+
val = %timeit -o tr.time_get_resolution(unit, size, tz)
16+
17+
df.loc[key] = (val.average, val.stdev)
18+
19+
"""
20+
from datetime import timedelta, timezone
21+
22+
from dateutil.tz import gettz, tzlocal
23+
import numpy as np
24+
import pytz
25+
26+
from pandas._libs.tslibs.resolution import get_resolution
27+
28+
29+
class TimeResolution:
30+
params = (
31+
["D", "h", "m", "s", "us", "ns"],
32+
[1, 100, 10 ** 4, 10 ** 6],
33+
[
34+
None,
35+
timezone.utc,
36+
timezone(timedelta(minutes=60)),
37+
pytz.timezone("US/Pacific"),
38+
gettz("Asia/Tokyo"),
39+
tzlocal(),
40+
],
41+
)
42+
param_names = ["unit", "size", "tz"]
43+
44+
def setup(self, unit, size, tz):
45+
arr = np.random.randint(0, 10, size=size, dtype="i8")
46+
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
47+
self.i8data = arr
48+
49+
def time_get_resolution(self, unit, size, tz):
50+
get_resolution(self.i8data, tz)

0 commit comments

Comments
 (0)