我正在优化一些经常运行的Perl代码(每个文件每天一次).
评论是否会降低Perl脚本的速度?我的实验倾向于否:
use Benchmark;
timethese(20000000, {
'comments' => '$b=1;
# comment ... (100 times)
', 'nocomments' => '$b=1;'});
Run Code Online (Sandbox Code Playgroud)
提供几乎相同的值(除了噪音).
Benchmark: timing 10000000 iterations of comments, nocomments...
comments: 1 wallclock secs ( 0.53 usr + 0.00 sys = 0.53 CPU) @ 18832391.71/s (n=10000000)
nocomments: 0 wallclock secs ( 0.44 usr + 0.00 sys = 0.44 CPU) @ 22935779.82/s (n=10000000)
Benchmark: timing 20000000 iterations of comments, nocomments...
comments: 0 wallclock secs ( 0.86 usr + -0.01 sys = 0.84 CPU) @ 23696682.46/s …
Run Code Online (Sandbox Code Playgroud)