Skip to content

m1so/fastdatetime

Repository files navigation

fastdatetime

Like datetime, but fast 🚀

ImplementationInstallationFAQAcknowledgements

PyPI License

Implementation

strptime

In the pursuit of a faster strptime implementation, two backing Rust crates were chosen due to their popularity in the ecosystem – chrono and time.

Both impementations are exposed under the following methods:

  1. fastdatetime.strptime (based on time along with time-fmt)
  2. fastdatetime.chrono.strptime (based on chrono)

Initially, chrono seemed liked a drop-in replacement, however due to subtle differences of %f specifier the format argument needs to preprocessed to conform to the Python referece which incurs slight performance overhead as the format string needs to be scanned. Furthermore, even without this shortcoming, the parsing was slower compared to time.

What's also interesting is that time doesn't support strptime compatible inferface out of the box – fortunatelly time-fmt does (in addition, some fixes and new functionality was upstreamed to the crate).

parse

Oftentimes the date format is not known ahead of time, or it is not possible to infer it from a few samples. In Python, one would usually opt for using the dateutil package, which can deal with all sorts of edge cases and is very forgiving, however these guarantees come at a cost – in order for the results to not be ambiguous but accurate, the user can tweak a lot of options (is the day or year first, ...) and has to sacrifice performance.

Enter dtparse by Bradlee Speice, a rewrite of dateutil.parse in Rust. Going full circle, fastdatetime just exposes Python bindings to Bradlee's excellent crate. This yields ~15x faster parsing performance (657 vs 42 Kops/sec on M1 Pro).

Installation

TBD

FAQ

TBD

Acknowledgements

License

© 2022 Contributors of Project fastdatetime.

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.