Created
August 24, 2011 05:49
-
-
Save soh335/1167387 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
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; | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my $lat = rand(180) - 90; | |
my $lon = rand(360) - 180; | |
$memd->set("lat$i", $lat); | |
$memd->set("lon$i", $lon); | |
$memd->set("hash10_$i", $geohash_xs->encode( $lat, $lon, 10 ) ); | |
$memd->set("hash20_$i", $geohash_xs->encode( $lat, $lon, 20 ) ); | |
$memd->set("hash30_$i", $geohash_xs->encode( $lat, $lon, 30 ) ); | |
} | |
cmpthese 300 , { | |
latlon => sub { | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my $lat = $memd->get("lat$i"); | |
my $lon = $memd->get("lon$i"); | |
} | |
}, | |
multi_latlon => sub { | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my $vals = $memd->get_multi("lat$i", "lon$i"); | |
} | |
}, | |
geohash => sub { | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my $hash = $memd->get("hash10_$i"); | |
} | |
}, | |
geohash_xs_decode_10 => sub { | |
my $geohash = Geo::Hash::XS->new; | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my ($lat, $lon) = $geohash->decode($memd->get("hash10_$i")); | |
} | |
}, | |
geohash_xs_decode_20 => sub { | |
my $geohash = Geo::Hash::XS->new; | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my ($lat, $lon) = $geohash->decode($memd->get("hash20_$i")); | |
} | |
}, | |
geohash_xs_decode_30 => sub { | |
my $geohash = Geo::Hash::XS->new; | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my ($lat, $lon) = $geohash->decode($memd->get("hash30_$i")); | |
} | |
}, | |
geohash_pure_decode => sub { | |
my $geohash = Geo::Hash->new; | |
for ( my $i = 0; $i < $total; $i++ ) { | |
my ($lat, $lon) = $geohash->decode($memd->get("hash10_$i")); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
既知?
http://d.hatena.ne.jp/kazuhooku/20091015/1255612839