小编Rod*_*Luo的帖子

Perl速度:$ a = $ a.$ b和$ a.= $ b之间的差异

我已将所有代码和运行信息放在下面.处理非常长的字符串时,标题中的操作速度是不同的.为什么以及有多少其他操作显示相同的特征?(如果循环低于10 ^ 4,则差异可以忽略不计.)

?  ~  cat t1.pl
#!/usr/bin/env perl
$a = 'a';

$i = 0;
while ($i < 100000){
  $a .= 'a';
  $i++;
}

?  ~  time perl t1.pl
perl t1.pl  0.01s user 0.00s system 85% cpu 0.021 total



?  ~  cat t2.pl
#!/usr/bin/env perl
$a = 'a';

$i = 0;
while ($i < 100000){
  $a = $a.'a';
  $i++;
}

?  ~  time perl t2.pl
perl t2.pl  0.50s user 0.01s system 99% cpu 0.507 total
Run Code Online (Sandbox Code Playgroud)

perl performance operations

3
推荐指数
1
解决办法
126
查看次数

标签 统计

operations ×1

performance ×1

perl ×1