manishsaraan / email-validator

email syntax validator npm module. fast and pretty robust
The Unlicense
436 stars 80 forks source link

Regex test early on, remove redundant check #80

Open xoliver opened 1 year ago

xoliver commented 1 year ago

Hi! I noticed that the regex already enforces that there should only be an @ between two lumps of text, so an early check with the regex will:

houd1ni commented 1 year ago

Hi! Thank you for the idea! But is it really more performant to run the big regex than to create an array of two strings? Any tests ?

xoliver commented 1 year ago

Hi @houd1ni . Thanks for your comment. This is my thinking:

I'm not a JS benchmarking expert (or JS experienced!) but I found this out and put out an example here, based on the input used in the unit tests: https://www.measurethat.net/Benchmarks/Show/27639/0/email-validator-pr-80-benchmark

My proposal seems to be 50% faster image