Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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)

Replies are listed 'Best First'.
Re: Native Map faster than MCE::Map.
by LanX (Saint) on Jun 21, 2021 at 16:22 UTC

      Sure, I will use the code tag next time.

      As for the heavier workload, if I use a higher number, the program is "killed" by the OS (with or without MCE::Map). So not sure how to generate a "heavier" work load. Any pointers would be helpful.

        The job has to be heavier not the number of jobs.

        $_ * $_ is simply to fast to justify the overhead.

        Please read the thread I linked to AND the documentation of MCE::Map !

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery