Skip to content

Instantly share code, notes, and snippets.

@soh335
Created August 24, 2011 05:48
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 soh335/1167386 to your computer and use it in GitHub Desktop.
Save soh335/1167386 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use Benchmark qw/:all/;
use Cache::Memcached::Fast;
use Geo::Hash::XS;
use Geo::Hash;
my $memd = Cache::Memcached::Fast->new({
servers => ["localhost:11211"]
});
$memd->flush_all;
my $total = 1000;
my $geohash_xs = Geo::Hash::XS->new;
my $latlons = [];
push @$latlons, { lat => rand(180) - 90, lon => rand(360) - 180 } for 1 .. $total;
cmpthese 300 , {
latlon => sub {
my $i = 1;
for my $latlon (@$latlons) {
$memd->set("lat$i", $latlon->{lat});
$memd->set("lon$i", $latlon->{lon});
$i++;
}
},
multi_latlon => sub {
my $i = 1;
for my $latlon (@$latlons) {
$memd->set_multi(["lat$i", $latlon->{lat}], ["lon$i", $latlon->{lon}]);
$i++;
}
},
geohash_xs_decode_10 => sub {
my $i = 1;
my $geohash = Geo::Hash::XS->new;
for my $latlon (@$latlons) {
$memd->set("hash10_$i", $geohash->encode($latlon->{lat}, $latlon->{lon}, 10));
$i++;
}
},
geohash_xs_decode_20 => sub {
my $i = 1;
my $geohash = Geo::Hash::XS->new;
for my $latlon (@$latlons) {
$memd->set("hash20_$i", $geohash->encode($latlon->{lat}, $latlon->{lon}, 20));
$i++;
}
},
geohash_xs_decode_30 => sub {
my $i = 1;
my $geohash = Geo::Hash::XS->new;
for my $latlon (@$latlons) {
$memd->set("hash30_$i", $geohash->encode($latlon->{lat}, $latlon->{lon}, 30));
$i++;
}
},
geohash_pure_decode => sub {
my $i = 1;
my $geohash = Geo::Hash->new;
for my $latlon (@$latlons) {
$memd->set("hash10_pure_$i", $geohash->encode($latlon->{lat}, $latlon->{lon}, 10));
$i++;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment