Created
April 10, 2012 22:47
-
-
Save sshaw/2355239 to your computer and use it in GitHub Desktop.
Locale::Country::Multilingual Benchmark
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
# Oops, here's the right benchmark snippet. | |
use Locale::Country::Multilingual; | |
use List::MoreUtils qw(zip pairwise); | |
use Benchmark 'timethese'; | |
use Unicode::Collate; | |
my $lcm = Locale::Country::Multilingual->new; | |
my $c = Unicode::Collate->new; | |
my ($lang, $format) = qw(en_US LOCALE_CODE_ALPHA_2); | |
# country2code is sooo slow, 100 should be fine | |
timethese(100, { | |
'zip+pairwise' => sub { | |
my @codes = $lcm->all_country_codes($format); | |
my @names = $lcm->all_country_names($lang); | |
my %countries = zip @names, @codes; | |
my @sorted_names = $c->sort(keys %countries); | |
my @sorted_codes = @countries{@sorted_names}; | |
my @options = pairwise { | |
my $option = [ $a, $b ]; | |
push @$option, selected => "selected" if $b eq 'BR'; | |
$option; | |
} @sorted_names, @sorted_codes; | |
}, | |
for => sub { | |
my @names = $lcm->all_country_names($lang); | |
my %options; | |
for (@names) { | |
$options{$_} = $lcm->country2code($_, $format, $lang); | |
} | |
}}); |
Author
sshaw
commented
Apr 10, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment