PERF: typing and cdefs for tslibs.resolution
State: closed

Moving things lower-level will help improve performance (due in part to better Cython compilation).

Labels:
name: Datetime
description: Datetime data dtype
name: Performance
description: Memory or execution speed performance
name: Internals
description: Related to non-user accessible pandas implementation

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=h1) Report
> Merging [#21452](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ab668b0a56a9f2aee959bde787e9a0af4068d7a7?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/21452/graphs/tree.svg?width=650&src=pr&token=eZ4WkYLtcO&height=150)](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #21452      +/-   ##
==========================================
+ Coverage   91.89%    91.9%   +<.01%     
==========================================
  Files         153      153              
  Lines       49600    49606       +6     
==========================================
+ Hits        45580    45589       +9     
+ Misses       4020     4017       -3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.3% <ø> (ø)` | :arrow_up: |
| #single | `41.89% <ø> (+0.02%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/21452/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.8% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/21452/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.62% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/category.py](https://codecov.io/gh/pandas-dev/pandas/pull/21452/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9jYXRlZ29yeS5weQ==) | `97.06% <0%> (+0.03%)` | :arrow_up: |
| [pandas/tseries/offsets.py](https://codecov.io/gh/pandas-dev/pandas/pull/21452/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvb2Zmc2V0cy5weQ==) | `97.24% <0%> (+0.24%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=footer). Last update [ab668b0...bf67f17](https://codecov.io/gh/pandas-dev/pandas/pull/21452?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jbrockmendel : I feel like the performance help is relatively obvious given that you are moving things underneath the Python level.  Is there any `asv` that could illustrate this by any chance (not a blocker, but just curious)?  If so, that might be worthwhile to include in a `whatsnew`.
`%timeit` results are insignificantly sped up:

```
now = pd.Timestamp.now()
dti = pd.DatetimeIndex([now + pd.Timedelta(seconds=19*n) for n in range(10**5)])
dti.inferred_freq  # creates _cache attr

def infer():
    dti._cache.clear()
    return dti.inferred_freq
```

Status quo results for `%timeit infer()`, in microseconds:
958, 957, 961, 964, 956, 959, 964

PR:
962, 958, 954, 953, 954, 956, 957

Note that in 0.23.0 it looks like these come back closer to 832.  No idea what changed in the interim.
thanks!