1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/usr/bin/env perl use warnings; use strict; use Term::ReadKey; Term::ReadKey::ReadMode 4; print ": "; my $c = ReadKey; if ( $c =~ /[0-9]/ ) { print "$c\n"; } print ": "; $c = ReadKey; if ( $c =~ /^[0-9]\z/ ) { print "$c\n"; } Term::ReadKey::ReadMode 0;
1
2
3
4
C:\>perl -MDevel::Size -E"print Devel::Size::total_size([0..9])"
240
C:\>perl -MDevel::Size -E"print Devel::Size::total_size(qr{^\d$})"
88
1
2
3
4
5
6
7
8
9
10
11
12
C:\>perl -MO=Concise -E"print '1' ~~ [0..9]"
b <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 46 -e:1) v:%,{ ->3
a <@> print vK ->b
3 <0> pushmark s ->4
9 <2> smartmatch sK/2 ->a
4 <$> const[PV "1"] s ->5
8 <@> anonlist sK*/1 ->9
5 <0> pushmark s ->6
7 <1> rv2av lKP/1 ->8
6 <$> const[AV ] s ->7
1
2
3
4
5
6
7
8
C:\>perl -MO=Concise -E"print '1' =~ /^\d$/"
7 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 46 -e:1) v:%,{ ->3
6 <@> print vK ->7
3 <0> pushmark s ->4
5 </> match(/"^\\d$"/) lKS/RTIME ->6
4 <$> const[PV "1"] s ->5
1
2
3
4
5
6
7
8
C:\>perl -MBenchmark -E"Benchmark::cmpthese(1000000, { 'Regex'=>sub {print '1' =~ /^\d$/}, 'Liste'=>sub{p
rint '1' ~~ [0..9]} })"
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
...
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111111 Rate Liste Regex
Liste 436110/s -- -71%
Regex 1490313/s 242% --