Skip to content
Advertisement

A faster strptime?

I have code which reads vast numbers of dates in ‘YYYY-MM-DD’ format. Parsing all these dates, so that it can add one, two, or three days then write back in the same format is slowing things down quite considerably.

JavaScript

Any suggestions how to speed it up a bit (or a lot)?

Advertisement

Answer

Python 3.7+: fromisoformat()

Since Python 3.7, the datetime class has a method fromisoformat. It should be noted that this can also be applied to this question:

Performance vs. strptime()

Explicit string slicing may give you about a 9x increase in performance compared to normal strptime, but you can get about a 90x increase with the built-in fromisoformat method!

JavaScript
JavaScript

Python 3.8.3rc1 x64 / Win10

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement