$ perl testGreed.pl Benchmark: running greedyLong, greedyShort, notGreedyLong, notGreedyShort, each for at least 3 CPU seconds... greedyLong: 3 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @ 42264.23/s (n=127004) greedyShort: 4 wallclock secs ( 3.20 usr + 0.01 sys = 3.21 CPU) @ 88692.45/s (n=284348) notGreedyLong: 4 wallclock secs ( 3.13 usr + 0.01 sys = 3.14 CPU) @ 46018.76/s (n=144729) notGreedyShort: 3 wallclock secs ( 2.99 usr + 0.01 sys = 3.00 CPU) @ 101593.68/s (n=305289) Rate greedyLong notGreedyLong greedyShort notGreedyShort greedyLong 42264/s -- -8% -52% -58% notGreedyLong 46019/s 9% -- -48% -55% greedyShort 88692/s 110% 93% -- -13% notGreedyShort 101594/s 140% 121% 15% -- #### #!/usr/bin/perl -w use strict; use Benchmark qw(cmpthese); my $i=0; my $varshort = "xxx:12345 yyy:54321 zzz:13245"; my $varlong = ("$varshort "x120); sub greedy { $_[0]=~m/.+\:(.+?)\s.+\:(.+?)\s.+\:(.+?)/; } sub notGreedy { $_[0]=~m/.+\:(.+?)\s.+?\:(.+?)\s.+?\:(.+?)/; } sub greedyShort { greedy($varshort); } sub greedyLong { greedy($varlong); } sub notGreedyShort { notGreedy($varshort); } sub notGreedyLong { notGreedy($varlong); } cmpthese(-3, { greedyShort => \&greedyShort, greedyLong => \&greedyLong, notGreedyShort => \¬GreedyShort, notGreedyLong => \¬GreedyLong, } );