Last active
January 24, 2022 11:53
-
-
Save cynovg/d429886345d7d24c9bd437a8fe351daf to your computer and use it in GitHub Desktop.
closure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use v5.16; | |
use Benchmark qw(:all); | |
timethese( | |
10000000, | |
{ | |
cycle => sub { | |
# test 2 | |
my @best; | |
push @best, $_ for 1 .. 10; | |
return @best; | |
}, | |
closure => sub { | |
# test 1 | |
my $test = sub { | |
my @best; | |
push @best, $_ for 1 .. 10; | |
return @best; | |
}; | |
return $test->(); | |
}, | |
real => sub { | |
my @best; | |
my $test = sub { | |
push @best, $_ for 1 .. 10; | |
}; | |
$test->(); | |
return @best; | |
}, | |
} | |
); |
Author
cynovg
commented
Apr 11, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment