Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optimization] CTRE slower than boost regex for validate emails #278

Open
raidenluikang opened this issue Feb 26, 2023 · 1 comment
Open

Comments

@raidenluikang
Copy link

raidenluikang commented Feb 26, 2023

CTRE: latest main branch current moment.

for validate email I use: (?:(?:[^<>()\[\].,;:\s@"]+(?:\.[^<>()\[\].,;:\s@"]+)*)|".+")@(?:(?:[^<>()\[\].,;:\s@"]+\.)+[^<>()\[\].,;:\s@"]{2,}) regex.

Let attached file (extension changed to LOG, because can't attach .cpp file):
example.LOG

Build: $ clang++ -o example example.cpp -O2 -std=c++20 -stdlib=libc++ -Wall -Wextra -Werror -Wpedantic

Result in my PC i5-11400, 16GB RAM ubuntu 20.04 Clang 15.07:

$ ./example 
STD: less_valid = 1  upp_valid = 1
BOOST: less_valid = 1  upp_valid = 1
CTRE: less_valid = 1  upp_valid = 1
====================================================
STD: valid_count = 21907
STD: elapsed time = 2.431440970
STD: is_valid_email took 2431 nanoseconds
=====================================================
BOOST: valid_count = 21907
BOOST: elapsed time = 0.361886186
BOOST: is_valid_email took 361 nanoseconds
=====================================================
CTRE: valid_count = 21907
CTRE: elapsed time = 1.335482155
CTRE: is_valid_email took 1335 nanoseconds
====================================================
ME: valid_count = 21907
ME: elapsed time = 0.042453908
ME: is_valid_email took 42 nanoseconds

CTRE took 1335 ns per call is_valid_email_ctre, boost took 361 ns, which more than 3 times faster CTRE's.

Hint: CTRE become slower when I added quoted symbols to test emails data.


Result when built with g++11.0:

$ ./example
STD: less_valid = 1  upp_valid = 1
BOOST: less_valid = 1  upp_valid = 1
CTRE: less_valid = 1  upp_valid = 1
====================================================
STD: valid_count = 22071
STD: elapsed time = 1.210953864
STD: is_valid_email took 1210 nanoseconds
=====================================================
BOOST: valid_count = 22071
BOOST: elapsed time = 0.354756538
BOOST: is_valid_email took 354 nanoseconds
=====================================================
CTRE: valid_count = 22071
CTRE: elapsed time = 0.614597561
CTRE: is_valid_email took 614 nanoseconds
====================================================
ME: valid_count = 22071
ME: elapsed time = 0.039021986
ME: is_valid_email took 39 nanoseconds

Now CTRE ~2 times slower than Boost regex.

@raidenluikang
Copy link
Author

Seems CTRE slower when check "\.+" part of regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant