I've been reading about Captures and this paragraph intrigued me:
Inside a Signature, a Capture may be created by prefixing a sigilless parameter with a vertical bar |. This packs the remainder of the argument list into that parameter.
This sounds a lot like a **@
(non flattening) slurpy, so this concocted this test code:
my $limit=1_000_000;
my @a=1 xx 10000;
my @b=-1 xx 10000;
sub test1(|c){
1;
};
sub test2(**@c){
1;
};
{
for ^$limit {
test1(@b,@a);
}
say now - ENTER now;
}
{
for ^$limit {
test2(@b,@a);
}
say now - ENTER now;
}
A sample run gives durations of each test block:
0.82560328
2.6650674
The Capture certainly seems to have the performance advantage. Is there a down side to using a Capture
as a slurpy in this fashion? Have I over simplified the comparison?