use threads; # add line before loading MCE (to spin threads) 1 thread 12.473 seconds 4 threads 3.182 seconds 3.92x fork 1 process 7.331 seconds 4 processes 1.848 seconds 3.97x #### -rw-r--r--. 1 mario mario 80348000 Oct 9 22:15 nightfall.txt -rw-r--r--. 1 mario mario 20087000 Oct 9 22:12 nightfall1.txt -rw-r--r--. 1 mario mario 20087000 Oct 9 22:13 nightfall2.txt -rw-r--r--. 1 mario mario 20087000 Oct 9 22:13 nightfall3.txt -rw-r--r--. 1 mario mario 20087000 Oct 9 22:14 nightfall4.txt 0.000 secs Spawned child pid: 11194 for nightfall1.txt 0.000 secs This is child pid 11194 for nightfall1.txt. I am alive and working! 0.000 secs Spawned child pid: 11195 for nightfall2.txt 0.001 secs opened nightfall1.txt and nightfall1.out 0.001 secs Spawned child pid: 11196 for nightfall3.txt 0.001 secs This is child pid 11195 for nightfall2.txt. I am alive and working! 0.001 secs Spawned child pid: 11197 for nightfall4.txt 0.001 secs This is child pid 11196 for nightfall3.txt. I am alive and working! 0.001 secs opened nightfall2.txt and nightfall2.out 0.001 secs This is child pid 11197 for nightfall4.txt. I am alive and working! 0.001 secs opened nightfall3.txt and nightfall3.out 0.001 secs opened nightfall4.txt and nightfall4.out 2.243 secs Child 11194 finished working on nightfall1.txt! 2.261 secs Child 11197 finished working on nightfall4.txt! 2.274 secs Child 11196 finished working on nightfall3.txt! 2.275 secs Child 11195 finished working on nightfall2.txt! 2.276 secs Parenting talking...all my children are finished! Hooray! #### mce-process-entire-chunk.pl 1.848 seconds mce-process-line-by-line.pl 2.264 seconds 2.235 ~ 2.281 #### user_func => sub { # worker chunk routine my ($mce, $chunk_ref, $chunk_id) = @_; $$chunk_ref =~ tr/-!"#%&'()*,.\/:;?@\[\\\]_{}0123456789//d; $$chunk_ref =~ s/w(as|ere)/be/gi; $$chunk_ref =~ s/$RE1/ $W1{lc $1} /g; $$chunk_ref =~ s/$RE2/ $W2{lc $1} /g; $$chunk_ref =~ s/$RE3/ $W3{lc $1} /g; # Output orderly and serially. MCE->relay_lock; print $OUT_FH $$chunk_ref; $OUT_FH->flush; MCE->relay_unlock; } #### user_func => sub { # worker chunk routine my ($mce, $chunk_ref, $chunk_id) = @_; my $output = ''; open my $fh, '<', $chunk_ref; while (<$fh>) { tr/-!"#%&'()*,.\/:;?@\[\\\]_{}0123456789//d; s/w(as|ere)/be/gi; s/$RE1/ $W1{lc $1} /g; s/$RE2/ $W2{lc $1} /g; s/$RE3/ $W3{lc $1} /g; $output .= $_; } close $fh; # Output orderly and serially. MCE->relay_lock; print $OUT_FH $output; $OUT_FH->flush; MCE->relay_unlock; }