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 | |
by Anonymous Monk on Jun 21, 2021 at 16:35 UTC | |
by LanX (Saint) on Jun 21, 2021 at 16:42 UTC |