Hi Monks

I'm playing with MCE::Map to see if it's really faster than native map, but so far, native map seems to be faster...What am I doing wrong?

use strict; use warnings; use Time::HiRes qw (gettimeofday tv_interval); my @bignum = (1..100000000); my $native_map_start_time = [gettimeofday]; my @native_map = map { $_ * $_ } @bignum; my $native_elapsed_time = tv_interval($native_map_start_time); printf "The elapsed time with native map is %2.2f seconds\n", $native_ +elapsed_time;

The output is:

$ perl native_map.pl The elapsed time with native map is 8.57 seconds

When I try the same with the MCE::Map, it takes longer than native map.

use strict; use warnings; use MCE::Map; use Time::HiRes qw (gettimeofday tv_interval); my $mce_start_time = [gettimeofday]; my @mce_map = mce_map_s { $_ * $_ }1, 100000000; my $mce_elapsed = tv_interval($mce_start_time); printf "The elapsed time with MCE::map (mce_map_s) is %2.2f seconds\n" +, $mce_elapsed;

This takes way longer:

perl mce_map.pl The elapsed time with MCE::map (mce_map_s) is 25.34 seconds

When I run this on Perl 5.16.3, both the times are almost double. With 5.32.0 though, I get the outputs given above.

I am trying these on a laptop with Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz Processor and 16 GB RAM running Debian Buster with backported kernel as shown below:

uname -rv 5.10.0-0.bpo.7-amd64 #1 SMP Debian 5.10.40-1~bpo10+1 (2021-06-04)

In reply to Native Map faster than MCE::Map. by Anonymous Monk

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.