use strict; use warnings; use MCE::Flow; use MCE::Shared; use Time::HiRes qw[ time ]; my $start = time; my $fh = MCE::Shared->handle( "<:raw", $ARGV[ 0 ] ); my @seen; sub tally { my ($aref) = @_; for ( 0 .. 255 ) { $seen[$_] += $aref->[$_] if $aref->[$_]; } return; } mce_flow { max_workers => 8 }, sub { my @_seen; while( read( $fh, my $buf, 16384 * 4 ) ) { # the length check may be omitted with MCE::Shared 1.002+ last unless length($buf); ++$_seen[$_] for unpack 'C*', $buf; } MCE->do('tally', \@_seen); }; close $fh; printf "Took %f secs\n", time() - $start; # for ( 0 .. 255 ) { # printf "%c : %u\n", $_, $seen[$_] if $seen[$_]; # }