Debugging some code ended up testing the differences in the statements such as $counter=$counter + 1;
vs $counter+=1;
my $run=True;
my $counter=0;
my $sup=Supply.interval(1);
my $tap= $sup.tap({
$run=$_ < 10;
});
{
while $run {
#$counter+=1;
$counter=$counter + 1;
}
$tap.close;
say "Iterations per second: {$counter/(now - ENTER now)}"; #
}
I'm getting around 20% more iterations per second for $counter=$counter+1
compared to $counter+=1;
Whats happening in the background thats so different?
EDIT:
Interestingly when trying this with an array and hyper operators the performance is greatly increased when using the +=
.
eg
@counter=@counter>>+<<@value;
vs
@counter>>+=<<@value;
I get about 2.8 times the iterations of the loop using >>+=<<
with arrays of 10_000 elements.
As far as I can tell via the time
cmd there is minimal parallel execution in either case (total user + system is within 2% of real time).
Any insight on how/why this is would be great. Thanks!