You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Noticed a large difference between nqp version (3s) and HLL version (42s) of this code. Filing in case there are potential optimization opportunities waiting to be discovered.
This runs in 42s and if you change all the .AT-POS to [], it goes up to 1m3s
my int @instructions = 'day_05.input'.IO.slurp.words.map: *.Int;
my int $index = 0;
my int $stop = @instructions.elems;
my int $iterations = 0;
my int $jump;
while $index < $stop {
$jump = @instructions.AT-POS: $index;
$jump >= 3 ?? --@instructions.AT-POS: $index
!! ++@instructions.AT-POS: $index;
$index = $index + $jump;
++$iterations;
}
say $iterations;
While this runs in 3s:
use nqp;
nqp::stmts(
(my $ins := nqp::getattr('day_05.input'.IO.slurp.words.map(*.Int).eager.List,
List, '$!reified')),
(my int $index),
(my int $stop = nqp::elems($ins)),
(my int $jump),
(my int $iterations),
nqp::while(
nqp::islt_i($index, $stop),
nqp::stmts(
($jump = nqp::atpos($ins,$index)),
nqp::if(
nqp::isge_i($jump,3),
nqp::bindpos($ins,$index,nqp::sub_i(nqp::atpos($ins,$index),1)),
nqp::bindpos($ins,$index,nqp::add_i(nqp::atpos($ins,$index),1))),
($index = nqp::add_i($index,$jump)),
($iterations = nqp::add_i($iterations, 1)))),
nqp::say($iterations));
The text was updated successfully, but these errors were encountered:
Ran through the Perl 6 implementation of day 05 part 2 with the
help of #perl6, improving the performance from 1m20s to 0m13s.
Resulted in two new Rakudo issues for future improvements:
rakudo/rakudo#1328rakudo/rakudo#1329
Don't see anything odd about it in --target=optimize or the profile. The biggest culprit is AT-POS, which is JITed (but not OSRed, which is already mentioned on #1421)
Noticed a large difference between nqp version (3s) and HLL version (42s) of this code. Filing in case there are potential optimization opportunities waiting to be discovered.
With this input saved as
day_05.inputfileThis runs in 42s and if you change all the .AT-POS to
[], it goes up to 1m3sWhile this runs in 3s:
The text was updated successfully, but these errors were encountered: