有没有对比过Julia与Perl的字符串处理能力?

字符替换,模式搜索处理,两者差别好几倍。
如何优化?

julia 底层就用的 PCRE(libpcre2),觉得慢举几个例子看看。

1 个赞

@time begin
i=100000;
while (i>1)
string = “The cat sat on the mat”
string = replace(string, “a”=>“o”)
string = replace(string, “t”=>“L”)
println(string);
global i-=1;
end
end

#-----------------------------------

my $start=times;
my $i=100000;
while ($i>1) {
my $string = ‘The cat sat on the mat’;
$string =~ tr/at/oL/;
print “$string\n”;
$i–;
}
print times-$start,“\n”;

#-----------
BTW,如果 tr/ao/oa/, Julia又如何实现?

放到函数里,再benchmark?