pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.04k stars 2.11k forks source link

DateTimeParser Validation and Performance Improvements #4593

Closed andrewauclair closed 5 days ago

andrewauclair commented 1 week ago

Improvements for #4592.

Improve the validation of DateTimeParser by validating the numbers parsed for day, month, year, hour, minute, second, millis, and micros. The value 0 will be used if no digits were found for micros.

These changes create new instances of SyntaxException thrown by DateTimeParser::parse and DateTimeParser::parseTZD when the previously listed fields do not contain the required number of digits or the string of digits is not a valid number.

Improve performance by caching the RegularExpressions created in DateTimeFormat::isValid.

matejk commented 1 week ago

@andrewauclair Do you have any performance measurements with these changes compared to 1.13?

andrewauclair commented 6 days ago

@andrewauclair Do you have any performance measurements with these changes compared to 1.13?

Came up with the following when running in WSL with the code from issue #4592:

1.12.5: 0m0.063s 1.13.3: 0m11.991s (almost 200x slower?) this pr: 0m0.185s (3x slower, likely the regex match)

Switching to a format string that doesn't match one of the expected ones, to avoid regex matches (const auto format = Poco::DateTimeFormat::ISO8601_FRAC_FORMAT + " "):

1.12.5: 0m0.063s 1.13.3: 0m0.065s this pr: 0m0.085s