in reply to perl 5.36 and the for_list feature - a simple speed comparison
List::Util::pairmap would be an existing solution very similar to the new feature. It also seems to run quite quickly (but I can't compare it to for_list since I don't have a new-enough perl).
use List::Util qw/ pairmap /; sub a_pairmap { my $i; pairmap { $i += $b } @vals; return $i; }
Good Day,
Dean
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: perl 5.36 and the for_list feature - a simple speed comparison
by kcott (Archbishop) on Jun 21, 2022 at 21:30 UTC | |
G'day Dean, "List::Util::pairmap would be an existing solution very similar to the new feature. It also seems to run quite quickly (but I can't compare it to for_list since I don't have a new-enough perl)." No problem. I have v5.36.0 installed. I added your code to the OP benchmark code. Mine starts as follows. Refer to "perl5360delta: use v5.36" for why I removed the strict and warnings pragmata.
I then added:
I ran the benchmark five times. All results were pretty much the same; here's a median set:
In all runs, a_pairmap was second fastest; and, h_by_key was faster than h_each (which differs from the OP results). My environment:
— Ken | [reply] [d/l] [select] |
by swl (Parson) on Jun 21, 2022 at 22:51 UTC | |
Thanks for this. Updated code and results are in 11144924. | [reply] |
Re^2: perl 5.36 and the for_list feature - a simple speed comparison
by swl (Parson) on Jun 21, 2022 at 22:49 UTC | |
Thanks for that. List::Util::pairmap is a good suggestion. Below is some updated code to add your array code and a hash variant. The results of three runs follow. The conclusions wrt pairmap are pretty much the same as those of kcott in 11144922. A point of difference is that h_by_key remains slower in my case. I wonder if there are differences due to the compiler used to build the perls or there's something cygwin vs linux. My system details are at the end. Edit - the original code used say a_pairmap() twice. kcott++ for noting. Read more... (2 kB)
| [reply] [d/l] [select] |