#!/usr/bin/perl -w use strict; use Benchmark qw(cmpthese); my $i=0; sub capture { "test$i"=~/(est|\d)/; } sub noCapture { "test$i"=~/(?:est|\d)/; } sub noParens { "test$i"=~/est|\d/; } sub twoRegexen { "test$i"=~/est/ || "test$i"=~/\d/; } cmpthese(-3, { capture => \&capture, noCapture => \&noCapture, noParens => \&noParens, twoRegexen => \&twoRegexen, } ); #### $ perl testRegexen.pl Benchmark: running capture, noCapture, noParens, twoRegexen, each for at least 3 CPU seconds... capture: 4 wallclock secs ( 3.18 usr + 0.00 sys = 3.18 CPU) @ 728822.24/s (n=2320570) noCapture: 2 wallclock secs ( 3.10 usr + 0.01 sys = 3.11 CPU) @ 827692.26/s (n=2576606) noParens: 4 wallclock secs ( 3.14 usr + 0.01 sys = 3.15 CPU) @ 871936.55/s (n=2748344) twoRegexen: 4 wallclock secs ( 3.41 usr + -0.00 sys = 3.41 CPU) @ 1478048.90/s (n=5047537) Rate capture noCapture noParens twoRegexen capture 728822/s -- -12% -16% -51% noCapture 827692/s 14% -- -5% -44% noParens 871937/s 20% 5% -- -41% twoRegexen 1478049/s 103% 79% 70% --