3 ms·
Raku regex performance sucks, for one. Let's parse some data into a hash in Perl: %words = ($input =~ /([^\n\t]+)\t(\N+)/g); In Raku, equivalent code wil
by cygx 6y ago
Raku regex performance sucks, for one.
Let's parse some data into a hash in Perl:
%words = ($input =~ /([^\n\t]+)\t(\N+)/g);
In Raku, equivalent code will be slower by an order of magnitude or more. The only way I've managed to get comparable performance is to write code like this:
use nqp;
my str $str = $input;
my int $pos = 0;
my int $chars = nqp::chars($str);
while $pos < $chars {
my int $tab = nqp::index($str, "\t", $pos);
my int $nl = nqp::index($str, "\n", $tab);
%words{nqp::p6box_s(nqp::substr($str, $pos, $tab - $pos))} =
nqp::p6box_s(nqp::substr($str, $tab + 1, $nl - $tab - 1));
$pos = $nl + 1;
}
Generally, the situation has been getting better, though. In contrast to the early days,
for $input.lines {
my $tab = .index("\t");
%words{.substr(0, $tab)} = .substr($tab + 1);
}
also performs adequately today.