#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $string = 'x'x5000; cmpthese -1, { substr => q[ for ( 0..length( $string)-1 ) { my $c = substr $string, $_, 1; } ], splitArray => q[ my @c=split'',$string; for( 0 .. $#c ){ my $c = $c[$_]; } ], splitFor => q[ for( split'', $string ){ my $c = $_; } ], unpack => q[ for( unpack 'C*', $string ) { my $c = chr; } ], reverseChop => q[ my $s = reverse $string; my $c; $c = $_ while chop $s; ], chop => q[ my $s = $string; my $c; $c = $_ while chop $s; ], ramfile => q[ open my $ram, '<', \$string; my $c; $c = $_ while $_ = getc( $ram ); ], }; __END__ C:\test>873068 Rate splitArray splitFor ramfile substr unpack reverseChop chop splitArray 169/s -- -48% -74% -81% -83% -89% -89% splitFor 323/s 91% -- -51% -64% -67% -79% -79% ramfile 654/s 288% 103% -- -27% -34% -57% -58% substr 891/s 428% 176% 36% -- -9% -42% -43% unpack 984/s 484% 205% 51% 10% -- -36% -37% reverseChop 1534/s 809% 376% 135% 72% 56% -- -1% chop 1555/s 822% 382% 138% 74% 58% 1% --