Perl: Why is it slower to declare (my) variables inside a loop?

后端 未结 5 1352
余生分开走
余生分开走 2021-01-12 20:58

What\'s the difference, from the interpreter\'s POV, between the following the following programs:

#!/usr/bin/perl -w

use strict;

for (1..10000000) {
    m         


        
5条回答
  •  无人及你
    2021-01-12 21:25

    The first loop attempts to make the variable declaration for every iteration of the loop and can result in unnecessary processing time.

    Granted, it's not much, but this stuff can add up over time, and it is technically slower since more instructions are executed per iteration.

提交回复
热议问题