notquiteamonad / date_time

date_time is a high-level Rust library for use in situations where precision beyond seconds is not necessary.
Apache License 2.0
8 stars 5 forks source link

Improve regex performance #58

Closed tuube closed 3 years ago

tuube commented 3 years ago

The current usage of Regex is very slow when used in a loop. Regex library docs tell us that compiling regex is quite expensive and should not be done in a loop. I fixed the issue by using lazy_static to create the regex instances, as the docs recommend.

I measured the time of 1000 runs of DateTuple::from_str() with both implementations, and the one with lazy_static wins clearly:

Also fixed typo in a comment.

notquiteamonad commented 3 years ago

Hi, thanks for your contribution! There haven't been commits here in a while and it looks like my CI is a bit broken :sweat_smile: but I'm happy with this PR so I'll merge it anyway and get a release out once I've fixed the other stuff later today

notquiteamonad commented 3 years ago

Thanks again, this is now available in version 2.1.1 :)

tuube commented 3 years ago

No problem, I'm glad to help 😄