perf improvements in tslibs.period
State: closed

Removes an unnecessary call to `frequencies.to_offset`, one of the last few non-cython dependencies in the file.

will post asv results when available.

Labels:
name: Datetime
description: Datetime data dtype
name: Performance
description: Memory or execution speed performance

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21447?src=pr&el=h1) Report
> Merging [#21447](https://codecov.io/gh/pandas-dev/pandas/pull/21447?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/bf1c3dc253c08e70c543ae09c146b72544e85df5?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master   #21447   +/-   ##
=======================================
  Coverage   91.89%   91.89%           
=======================================
  Files         153      153           
  Lines       49604    49604           
=======================================
  Hits        45584    45584           
  Misses       4020     4020
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.29% <ø> (ø)` | :arrow_up: |
| #single | `41.88% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/21447?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/21447?src=pr&el=footer). Last update [bf1c3dc...a3d11c6](https://codecov.io/gh/pandas-dev/pandas/pull/21447?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

> will post asv results when available.

@jbrockmendel : `whatsnew` entry in `0.24.0` + perf test would also be good here.
as isn't showing much (recall it is wonky on my machine for reasons unknown)

```
taskset 6 asv continuous -f 1.1 -E virtualenv master HEAD -b period
[...]
    before     after       ratio
  [defdb34b] [daf9aaf7]
-    3.26ms     2.82ms      0.87  period.PeriodIndexConstructor.time_from_pydatetime('D')

    before     after       ratio
  [defdb34b] [daf9aaf7]
+   87.34ms   147.38ms      1.69  gil.ParallelDatetimeFields.time_datetime_to_period
+  118.47ms   133.50ms      1.13  gil.ParallelDatetimeFields.time_period_to_datetime
+   35.94ms    39.66ms      1.10  period.DataFramePeriodColumn.time_setitem_period_column
-   66.75μs    60.54μs      0.91  period.PeriodProperties.time_property('min', 'start_time')
-   75.69μs    68.21μs      0.90  period.PeriodProperties.time_property('M', 'end_time')

    before     after       ratio
  [defdb34b] [daf9aaf7]
+  884.44ns     1.00μs      1.13  period.PeriodProperties.time_property('min', 'week')
-  143.83ms   116.09ms      0.81  gil.ParallelDatetimeFields.time_period_to_datetime
-  143.24ms    93.98ms      0.66  gil.ParallelDatetimeFields.time_datetime_to_period

    before     after       ratio
  [defdb34b] [daf9aaf7]
+  123.27ms   164.93ms      1.34  gil.ParallelDatetimeFields.time_period_to_datetime
-   19.73μs    17.71μs      0.90  period.PeriodUnaryMethods.time_asfreq('M')
-    1.03μs   879.73ns      0.85  period.PeriodProperties.time_property('M', 'is_leap_year')

    before     after       ratio
  [defdb34b] [daf9aaf7]
+  112.56ms   125.62ms      1.12  gil.ParallelDatetimeFields.time_datetime_to_period
-   40.44ms    36.20ms      0.89  period.DataFramePeriodColumn.time_setitem_period_column
```
thanks!