Just for kicks, I removed the print statement (as suggested by grinder) and threw in a ++$foo instead. Got the following: (Abigail's is still last but has the most ammount of votes still...)

Benchmark: timing 10000 iterations of abigail, grinder, posixguy, roge +r... abigail: 55 wallclock secs (51.42 usr + 0.12 sys = 51.54 CPU) @ 19 +4.02/s (n=10000) grinder: 1 wallclock secs ( 0.60 usr + 0.00 sys = 0.60 CPU) @ 16 +666.67/s (n=10000) posixguy: 1 wallclock secs ( 0.96 usr + 0.00 sys = 0.96 CPU) @ 10 +416.67/s (n=10000) roger: 1 wallclock secs ( 0.61 usr + 0.00 sys = 0.61 CPU) @ 16 +393.44/s (n=10000)

Updated code is in a readmore block (I removed the prints and added a $)

#!/usr/bin/perl -w use strict; use Benchmark; my @data = qw{1949 1950 1951 1999 2000 2001 2010 2049 2050 2051 2102 2 +2102 19534 19080 20010}; sub grinder() { my $foo = 0; foreach( @data ) { chomp; ++$foo if (/^(19[5-9]\d|20([0-4]\d|50))$/); } return $foo; } sub roger() { my $foo = 0; foreach (@data) { chomp; ++$foo if (/^(?:19|20)(?:(?:(?<=19)[5-9]|(?<=20)[0-4]) +[0-9]|50)$/x); } return $foo; } sub posixguy() { my $foo = 0; foreach (@data) { chomp; ++$foo if (/^(19[5-9]\d)|(20([0-4]\d)|50)$/); } return $foo; } sub abigail() { my $foo = 0; foreach (@data) { chomp; local $" = "|"; ++$foo if (/^(?:@{[1950 .. 2050]})$/); } return $foo; } timethese(10000, {grinder=>'grinder()', roger=>'roger()', posixguy=>'p +osixguy()', abigail=>'abigail()'});

In reply to Re: Re: Matching date range with pure regex by MCS
in thread Matching date range with pure regex by BUU

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.