use MCE::Loop max_workers => 4, chunk_size => 1;
## non-chunking takes 2m18s to complete
mce_loop {
MCE->say($_);
} 1..4_000_000;
####
use MCE::Loop max_workers => 4, chunk_size => 'auto';
## chunking takes 0m12s to complete (IPC becomes 11.5x faster)
mce_loop {
my ($mce, $chunk_ref, $chunk_id) = @_;
my @o; for (@{ $chunk_ref }) {
push @o, $_;
}
MCE->say(@o);
} 1..4_000_000;
####
use MCE::Loop max_workers => 4, chunk_size => 'auto';
## processing a file directly (mce_loop_f) takes 0m11.7s
mce_loop_f {
my ($mce, $chunk_ref, $chunk_id) = @_;
chomp @{ $chunk_ref };
my @o; for (@{ $chunk_ref }) {
push @o, $_;
}
MCE->say(@o);
} '/path/to/four_million_rows.txt';
####
## array non-chunking...: 1m54.467s
## array auto-chunking..: 0m 0.843s 136x
## file auto-chunking..: 0m 0.467s 245x
####
## array non-chunking...: 1m 5.458s
## array auto-chunking..: 0m 0.821s 80x
## file auto-chunking..: 0m 0.411s 159x
####
mce_loop_f {
MCE->last; # immediately leaves the block and input
...
} '/path/to/four_million_rows.txt';
####
## array non-chunking...: 1m 5.384s
## array auto-chunking..: 0m 0.747s 88x
## file auto-chunking..: 0m 0.337s 194x