why are function calls in Perl loops so slow?

前端 未结 4 1586
无人共我
无人共我 2021-02-02 15:18

I was writing a file parser in Perl, so had to loop through file. File consists of fixed length records and I wanted to make a separate function that parses given record and cal

4条回答
  •  滥情空心
    2021-02-02 15:35

    The perl optimizer is constant-folding the sprintf calls in your sample code.

    You can deparse it to see it happening:

    $ perl -MO=Deparse sample.pl
    foreach $_ (1 .. 10000000) {
        $a = &get_string();
    }
    sub get_string {
        return "abc\n";
    }
    foreach $_ (1 .. 10000000) {
        $a = "abc\n";
    }
    - syntax OK
    

提交回复
热议问题