In performing code review for an internal project, a question was raised as to the better method to validate email addresses against RFC822. Two techniques from separate projects were examined and benchmarked, one which uses Email::Valid::Loose and the other, Mail::RFC822::Address, the results of which follow.

The question which I have however is as to whether this benchmark valid? Is the benchmark code accurately measuring the relative validation techniques or is this comparison in some manner flawed? I am most interested in this, as the Benchmark results received differ from what I would have expected, particularly given the size and complexity of the $Addr_spec_re regular expression from Email::Valid::Loose.

The benchmark code:

use Benchmark; use Email::Valid::Loose; use Mail::RFC822::Address qw( valid ); my $iter = 100000; my @results = (); timethese($iter, { 'Mail::RFC822::Address' => <<EOS, \$result[0] = valid('per\@p'); \$result[1] = valid(''); \$result[2] = valid('email\@domain.com'); \$result[3] = valid('email\@email\@domain.com'); EOS 'Email::Valid::Loose' => <<EOS } ); (\$result[4]) = 'per\@p' =~ /\^($Email::Valid::Loose::Addr_spec_re)\$/ +; (\$result[5]) = '' =~ /\^($Email::Valid::Loose::Addr_spec_re)\$/; (\$result[6]) = 'email\@domain.com' =~ /\^($Email::Valid::Loose::Addr_ +spec_re)\$/; (\$result[7]) = 'email\@email\@domain.com' =~ /\^($Email::Valid::Loose +::Addr_spec_re)\$/; EOS

And the benchmark results:

Benchmark: timing 100000 iterations of Email::Valid::Loose, Mail::RFC8 +22::Address... Email::Valid::Loose: 6 wallclock secs ( 7.26 usr + 0.00 sys = 7.26 +CPU) @ 13774.10/s (n=100000) Mail::RFC822::Address: 28 wallclock secs (27.03 usr + 0.00 sys = 27.0 +3 CPU) @ 3699.59/s (n=100000)

 

perl -le "print unpack'N', pack'B32', '00000000000000000000001010111101'"


In reply to Benchmarking email address validation methods by rob_au

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.