Once upon a time, a fool thought, "I know! I'll fix this problem with a regular expression." Then he had two problems.

ssn-bench [master●] cargo bench
   Compiling ssn-bench v0.1.0 (file:///Users/archer/src/ssn-bench)
    Finished release [optimized] target(s) in 1.7 secs
     Running target/release/deps/ssn_bench-b1d7980aa727a85d

running 3 tests
test tests::can_create_ssn_validator ... ignored
test tests::ssn_struct_works ... ignored
test tests::ssn_validator_works ... ignored

test result: ok. 0 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out

     Running target/release/deps/perf-daa568d1d10662a9

running 2 tests
test non_regex_validator ... bench:           9 ns/iter (+/- 0)
test regex_validator     ... bench:       1,368 ns/iter (+/- 258)

test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured; 0 filtered out

In fairness, I'm not testing vs. the original regular expression used for this purpose. I simplified it by removing the first non-capturing group, because I couldn't even tell what it was for. Nonetheless, the non-regex version of the validator still runs 150 times faster.

no-regex