#!perl -w use strict; use Benchmark qw/cmpthese/; my %tran_types; foreach ('A'..'Z') { $tran_types{$_} = "" }; my $char_y = 'J'; # yes my $char_n = '_'; # no my $char_n_l = 'AA'; # no; too long my $char_n_A = '0'; # no; lt 'A' my $char_n_Z = 'a'; # no; gt 'Z' cmpthese(-(shift), { 're_Y' => sub { $char_y =~ /^[A-Z]\z/ }, 're_n' => sub { $char_n =~ /^[A-Z]\z/ }, 'co_Y' => sub { length $char_y == 1 and $char_y ge "A" and $char_y le "Z" }, 'co_nA' => sub { length $char_n_A == 1 and $char_n_A ge "A" and $char_n_A le "Z" }, 'co_nZ' => sub { length $char_n_Z == 1 and $char_n_Z ge "A" and $char_n_Z le "Z" }, 'co_nl' => sub { length $char_n_l == 1 and $char_n_l ge "A" and $char_n_l le "Z" }, 'ex_Y' => sub { exists $tran_types{$char_y} }, 'ex_n' => sub { exists $tran_types{$char_n} }, }); #### Benchmark: running co_Y, co_nA, co_nZ, co_nl, ex_Y, ex_n, re_Y, re_n, each for at least 15 CPU seconds... co_Y: 18 wallclock secs (14.95 usr + 0.05 sys = 15.00 CPU) @ 266935.00/s (n=4004025) co_nA: 15 wallclock secs (15.63 usr + -0.03 sys = 15.60 CPU) @ 355186.35/s (n=5540907) co_nZ: 18 wallclock secs (15.71 usr + 0.10 sys = 15.81 CPU) @ 262582.80/s (n=4151434) co_nl: 17 wallclock secs (16.12 usr + -0.09 sys = 16.03 CPU) @ 720797.75/s (n=11554388) ex_Y: 14 wallclock secs (16.11 usr + -0.02 sys = 16.09 CPU) @ 712203.05/s (n=11459347) ex_n: 14 wallclock secs (16.72 usr + -0.62 sys = 16.10 CPU) @ 862264.35/s (n=13882456) re_Y: 16 wallclock secs (15.18 usr + 0.12 sys = 15.30 CPU) @ 202467.06/s (n=3097746) re_n: 17 wallclock secs (15.97 usr + -0.02 sys = 15.95 CPU) @ 243489.40/s (n=3883656) Rate re_Y re_n co_nZ co_Y co_nA ex_Y co_nl ex_n re_Y 202467/s -- -17% -23% -24% -43% -72% -72% -77% re_n 243489/s 20% -- -7% -9% -31% -66% -66% -72% co_nZ 262583/s 30% 8% -- -2% -26% -63% -64% -70% co_Y 266935/s 32% 10% 2% -- -25% -63% -63% -69% co_nA 355186/s 75% 46% 35% 33% -- -50% -51% -59% ex_Y 712203/s 252% 192% 171% 167% 101% -- -1% -17% co_nl 720798/s 256% 196% 175% 170% 103% 1% -- -16% ex_n 862264/s 326% 254% 228% 223% 143% 21% 20% --