Whew! That's hard to read. But -- hoping I've read it correctly,
#!C:/perl/bin -w use strict; # regextiming.pl use vars qw( $string $ms $ms2 ); $string = "fred and barney went bowling last night"; { $ms = Win32::GetTickCount(); if ( $string =~ /fred.+barney/) { } else { print "No match\n\n"; } print "This match used ",Win32::GetTickCount() - $ms, " ticks on a w2k + box\n\n"; } # alt --OP expects this to be quicker { $ms2 = Win32::GetTickCount(); if ( $string =~ /fred.+?barney/) { } else { print "No match via second refex\n\n"; exit(); } print "The non-greedy match used ",Win32::GetTickCount() - $ms2, " tic +ks on a w2k box.\n"; }

OUTPUT:
F:\_wo\pl_test>perl regextiming.pl
This match used 0 ticks on a w2k box

The non-greedy match used 0 ticks on a w2k box

Update:fixed spelling, grammar Prior discussion found with a casual search suggests that the identical timines times, to no_better_than one millisecond, is are or was were a limitation of w32. Opinion was divided as to whether Time::HiRes could do better.

So...

# regextiming2.pl #!C:/perl/bin -w use strict; use Time::HiRes 'time'; # regextiming2.pl use vars qw( $string $start $start2 $end $end2 ); $string = "fred and barney went bowling last night"; { $start = time(); if ( $string =~ /fred.+barney/) { } else { print "No match\n\n"; } $end = time(); print "This match used ",$end - $start, " as measured by Time::HiRes o +n a w2k box\n\n"; } { $start2 = time(); if ( $string =~ /fred.+barney/) { } else { print "No match\n\n"; } $end2 = time(); print "The second match used ",$end2 - $start2, " as measured by Time: +:HiRes on a w2k box\n\n"; }

OUTPUT2:

F:\_wo\pl_test>perl regextiming2.pl
This match used 1.00135803222656e-005 as measured by Time::HiRes on a w2k box

The second match used 6.91413879394531e-006 as measured by Time::HiRes on a w2k box

QED ... I hope.


In reply to Re: About Greedy and Non-Greedy Regular Expressions by ww
in thread About Greedy and Non-Greedy Regular Expressions by PerlPhi

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.