in reply to Convert string to array - performance challenge
Rate regex unpack_C unpack_a split regex 9.95/s -- -2% -46% -50% unpack_C 10.1/s 2% -- -45% -49% unpack_a 18.3/s 84% 80% -- -9% split 20.0/s 101% 97% 9% --
use strict; use warnings; use Benchmark qw( cmpthese ); my %tests = ( split => q{ my @a = split //, $buf; }, regex => q{ my @a = $buf =~ /./sg; }, unpack_C => q{ my @a = map chr, unpack 'C*', $buf; }, unpack_a => q{ my @a = unpack '(a)*', $buf; }, ); $_ = "use strict; use warnings; our \$buf; $_ 1" for values(%tests); local our $buf = "abcdef\x00ghik" x 10_000; cmpthese(-2, \%tests);
Update: Changed (A)* to (a)* in response to BrowserUk's reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Convert string to array - performance challenge
by BrowserUk (Patriarch) on Apr 07, 2010 at 17:55 UTC | |
|
Re^2: Convert string to array - performance challenge
by Marshall (Canon) on Apr 08, 2010 at 06:52 UTC | |
by Anonymous Monk on Apr 08, 2010 at 07:08 UTC | |
by BrowserUk (Patriarch) on Apr 08, 2010 at 07:23 UTC | |
by ikegami (Patriarch) on Apr 08, 2010 at 16:54 UTC |