Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created July 5, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujiwara/d879bb48424bc902619ebe1dd2c2ffcc to your computer and use it in GitHub Desktop.
Save fujiwara/d879bb48424bc902619ebe1dd2c2ffcc to your computer and use it in GitHub Desktop.
use 5.12.0;
use Benchmark qw/:all/;
my @src = 1 .. 1000;
cmpthese 0, {
push => sub {
my @dest;
for (@src) {
push @dest, $_;
}
},
map => sub {
my @dest = map { $_ } @src;
},
};
$ perl -v
This is perl 5, version 26, subversion 0 (v5.26.0) built for darwin-2level
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2017, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
$ perl b.pl
Rate push map
push 14034/s -- -1%
map 14175/s 1% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment