Last active
December 23, 2020 19:15
-
-
Save bessarabov/2eabb33b162cc11bad97c2ccf9e6f2e4 to your computer and use it in GitHub Desktop.
This file contains 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 strict; | |
use warnings; | |
use Benchmark qw(cmpthese); | |
cmpthese( | |
-5, | |
{ | |
array => sub { | |
my @arr; | |
foreach my $i (1..500) { | |
$arr[$i] = $i; | |
} | |
}, | |
hash => sub { | |
my %h; | |
foreach my $i (1..500) { | |
$h{$i} = $i; | |
} | |
}, | |
}, | |
); | |
__END__ | |
$ perl perl_benchmark_array_hash_write.pl | |
Rate hash array | |
hash 3613/s -- -87% | |
array 27587/s 664% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment