| Issue |
60991
|
| Summary |
libc++ std::regex and std::regex_match very slow, ~10x slower than libstdc++
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
raidenluikang
|
I searched for issues but didn't find anything like it.
Let https://godbolt.org/z/o5Wx9x3Gq
```
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctre.hpp>
#include <string_view>
#include <regex>
#include <chrono>
#include <string>
#include <vector>
bool is_valid_email_ctre (const std::string& email)
{
return (bool)ctre::match<R"rx((?:(?:[^<>()\[\].,;:\s@"]+(?:\.[^<>()\[\].,;:\s@"]+)*)|".+")@(?:(?:[^<>()\[\].,;:\s@"]+\.)+[^<>()\[\].,;:\s@"]{2,}))rx">(email);
}
bool is_valid_email(const std::string& email)
{
static const std::regex rx{R"rx((?:(?:[^<>()\[\].,;:\s@"]+(?:\.[^<>()\[\].,;:\s@"]+)*)|".+")@(?:(?:[^<>()\[\].,;:\s@"]+\.)+[^<>()\[\].,;:\s@"]{2,}))rx"};
return std::regex_match(email, rx);
}
//......
```
Clang libc++ output:
```
STD: less_valid = 1 upp_valid = 1
CTRE: less_valid = 1 upp_valid = 1
STD: valid_count = 4291
STD: elapsed time = 1.147848643
STD: is_valid_email took 11478 nanoseconds
CTRE: valid_count = 4291
CTRE: elapsed time = 0.038445505
CTRE: is_valid_email took 384 nanoseconds
```
GCC libstdc++ output:
```
STD: less_valid = 1 upp_valid = 1
CTRE: less_valid = 1 upp_valid = 1
STD: valid_count = 4245
STD: elapsed time = 0.116426089
STD: is_valid_email took 1164 nanoseconds
CTRE: valid_count = 4245
CTRE: elapsed time = 0.010598227
CTRE: is_valid_email took 105 nanoseconds
```
libc++ STD: elapsed time = 1.147848643 s vs libstdc++ STD elapsed time = 0.116426089, - which 9.86 times slower.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs