Sometimes, I like to know "really" what the overhead is for MCE. So, here is something to measure the chunking nature of MCE. Simply comment out user_begin, user_end, and the process routine. That's it.

#!/usr/bin/env perl use strict; use warnings; use MCE; use Time::HiRes 'time'; die "usage: $0 infile1.txt\n" unless @ARGV; my $OUT_FH; # output file-handle used by workers # Spawn worker pool. my $mce = MCE->new( max_workers => MCE::Util::get_ncpu(), chunk_size => '64K', init_relay => 0, # specifying init_relay loads MCE::Relay use_slurpio => 1, # enable slurpio # user_begin => sub { # # worker begin routine per each file to be processed # my ($outfile) = @{ MCE->user_args() }; # open $OUT_FH, '>>', $outfile; # }, # user_end => sub { # # worker end routine per each file to be processed # close $OUT_FH if defined $OUT_FH; # }, user_func => sub { # worker chunk routine my ($mce, $chunk_ref, $chunk_id) = @_; # process_chunk($chunk_ref); } )->spawn; my $start = time; $mce->process($ARGV[0]); printf "%0.3f seconds\n", time - $start;

I have a big file which is 767 MB. The overhead is a fraction of a second.

$ ls -lh big.txt -rw-r--r-- 1 mario mario 767M Oct 5 10:07 big.txt $ perl demo.pl big.txt 0.154 seconds

Edit: That was from OS level cache as I had read the file from prior testing.


In reply to Re^2: Need to speed up many regex substitutions and somehow make them a here-doc list (MCE solution) by marioroy
in thread Need to speed up many regex substitutions and somehow make them a here-doc list by xnous

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.