1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| $ perl -MBenchmark="timethese,cmpthese" -e'for (1, 10, 100, 1000, 10000) { my $aa = 0; my $bb = 0; my $s = "A122A32T23AGT44" x $_; print "---- chaine de taille ", length($s), "\n"; $r = timethese( 1000000 / $_, { split => sub {++$aa for split /(?<=\D)|(?=\D)/, $s}, match => sub{++$bb for $s =~ m/(\d+|\w)/g}, } ); cmpthese $r; die if $aa != $bb or $aa != 10000000}'
---- chaine de taille 15
Benchmark: timing 1000000 iterations of match, split...
match: 8 wallclock secs ( 7.43 usr + 0.00 sys = 7.43 CPU) @ 134589.50/s (n=1000000)
split: 11 wallclock secs (10.33 usr + 0.01 sys = 10.34 CPU) @ 96711.80/s (n=1000000)
Rate split match
split 96712/s -- -28%
match 134590/s 39% --
---- chaine de taille 150
Benchmark: timing 100000 iterations of match, split...
match: 7 wallclock secs ( 6.59 usr + 0.00 sys = 6.59 CPU) @ 15174.51/s (n=100000)
split: 9 wallclock secs ( 9.05 usr + 0.00 sys = 9.05 CPU) @ 11049.72/s (n=100000)
Rate split match
split 11050/s -- -27%
match 15175/s 37% --
---- chaine de taille 1500
Benchmark: timing 10000 iterations of match, split...
match: 7 wallclock secs ( 6.53 usr + 0.00 sys = 6.53 CPU) @ 1531.39/s (n=10000)
split: 9 wallclock secs ( 9.09 usr + 0.00 sys = 9.09 CPU) @ 1100.11/s (n=10000)
Rate split match
split 1100/s -- -28%
match 1531/s 39% --
---- chaine de taille 15000
Benchmark: timing 1000 iterations of match, split...
match: 7 wallclock secs ( 6.52 usr + 0.00 sys = 6.52 CPU) @ 153.37/s (n=1000)
split: 9 wallclock secs ( 9.08 usr + 0.00 sys = 9.08 CPU) @ 110.13/s (n=1000)
Rate split match
split 110/s -- -28%
match 153/s 39% --
---- chaine de taille 150000
Benchmark: timing 100 iterations of match, split...
match: 7 wallclock secs ( 6.18 usr + 0.01 sys = 6.19 CPU) @ 16.16/s (n=100)
split: 9 wallclock secs ( 8.77 usr + 0.01 sys = 8.78 CPU) @ 11.39/s (n=100)
Rate split match
split 11.4/s -- -29%
match 16.2/s 42% --
$ |
Partager