File: closure.pl

package info (click to toggle)
libdevel-nytprof-perl 6.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,888 kB
  • sloc: perl: 5,497; javascript: 4,033; ansic: 107; makefile: 27
file content (18 lines) | stat: -rw-r--r-- 428 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


our $o;

for my $i (1..100_000) {

    my $named2 = \&bar; sub bar { return 1; 1+$l }  # non-closure
    my $named1 = \&foo; sub foo { return 1; 1+$o }  # non-closure
    my $anon1  =        sub     { return 1; 1+$o }; # non-closure
    my $anon2  =        sub     { return 1; 1+$l }; # closure

    $named2->();
    $named1->(); # faster because of cpu cache of opcode logic?
    $anon1->();
    $anon2->();

    1; # loop
}