PERF: consolidate imports inside parse_time_string by qwhelan · Pull Request #24084 · pandas-dev/pandas (original) (raw)

This PR adds an asv benchmark for the creation of Period objects directly from integers, and an associated speedup for the same case.

When calling Period._from_ordinal(), the runtime is unfortunately dominated by a pair of import statements needed to pull in the global config settings display.date_dayfirst and display.date_yearfirst. Thus, simply consolidating them leads to a significant speedup:

Benchmarks that have improved:

       before           after         ratio
     [08395af4]       [696b40f1]
     <parse_time_string~1>       <parse_time_string>
-         176±3ms         98.7±3ms     0.56  period.PeriodIndexConstructor.time_from_ints('D')