The regex variant tested slightly slower on my machine, compared to the array-unpack-reduce demonstration.

# rtoa-pgatram-mce.pl # Example run: perl rtoa-pgatram-mce.pl t1.txt >mce.tmp # # Convert a "modern" Roman Numeral to its arabic (decimal) equivalent. # The alpabetic input string may be assumed to always contain a valid +Roman Numeral in the range 1-3999. # Roman numerals may be upper or lower case. # Error handling is not required. # For example: # input "XLII" should produce the arabic (decimal) value 42 # input "mi" should produce the arabic (decimal) value 1001 use strict; use warnings; use List::Util qw(sum); use Time::HiRes qw(time); use MCE; # Function roman_to_arabic # Output a list of their arabic (decimal) values to standard output. # sub roman_to_arabic { my $files = shift; # in: reference to a list of files containin +g Roman Numerals (one per line) my $apply_cpu_affinity = ( $^O =~ /linux/i ) ? 1 : 0; my %r2d; @r2d{qw( i ii iii iv v vi vii viii ix x xx xxx xl l lx lxx lxxx xc c cc ccc cd d dc dcc dccc cm m mm mmm )} = map { my $n = $_; map $n * $_, 1 .. 9 } 1, 10, 100, 1000; my $re = qr/ ix|iv|iii|ii|i| viii|vii|vi|v| xxx|xx|xl|xc|x| lxxx|lxx|lx|l| cm|cd|ccc|cc|c| dccc|dcc|dc|d| mmm|mm|m| ./x; # construct a pool of workers my $mce = MCE->new( max_workers => MCE::Util::get_ncpu(), chunk_size => 90 * 1024, init_relay => 1, # if defined, tells MCE to load MCE::Relay p +lus extra setup posix_exit => 1, use_slurpio => 1, user_begin => sub { if ( $apply_cpu_affinity ) { my $cpu = (MCE->wid - 1) % MCE::Util::get_ncpu(); system("taskset -cp $cpu $$ >/dev/null"); $apply_cpu_affinity = 0; } }, user_func => sub { my ( $mce, $slurp_ref, $chunk_id, $output ) = ( @_, '' ); open my $fh, '<', $slurp_ref; while ( <$fh> ) { chomp; $output .= sum @r2d{ (lc $_) =~ /$re/go }; $output .= "\n"; } close $fh; # output orderly MCE::relay { print $output }; } ); # process a list of files for my $fname ( @{$files} ) { warn("$0: cannot access '$fname': No such file or directory\n"), + next unless -e $fname; warn("$0: cannot access '$fname': Permission denied\n"), next unless -r $fname; warn("$0: cannot process '$fname': Is a directory\n"), next if -d $fname; $mce->process({ input_data => $fname }); } # reap MCE workers $mce->shutdown; } @ARGV or die "usage: $0 file...\n"; my @rtoa_files = @ARGV; warn "rtoa pgatram start\n"; my $tstart = time; roman_to_arabic(\@rtoa_files); warn sprintf("time %0.03f secs\n", time - $tstart);

Running with one worker.

# max_workers => 1 time reduce : 4.581 secs time regex : 4.658 secs

In reply to Re^2: Risque Romantic Rosetta Roman Race - MCE Hash Regex by marioroy
in thread Risque Romantic Rosetta Roman Race by eyepopslikeamosquito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.