Algorithm-SpatialIndex-Storage-Redis
view release on metacpan or search on metacpan
examples/bench.pl view on Meta::CPAN
use strict;
use warnings;
use lib 'lib';
use Algorithm::SpatialIndex;
use Algorithm::SpatialIndex::Storage::Redis;
use lib 't/lib';
use Algorithm::SpatialIndex::Test;
use Algorithm::QuadTree;
use Benchmark qw(cmpthese timethese);
my $redis_cfg = test_redis_config();
die if not $redis_cfg;
# ordered or random or concentrated_random
#my $item_mode = 'ordered';
#my $item_mode = 'random';
my $item_mode = 'concentrated_random';
my $use_median_qtree = eval {
use Algorithm::SpatialIndex::Strategy::MedianQuadTree;
1;
};
my $bucks = 100;
my $scale = 4;
my $depth = 10;
my @limits = qw(-10 -10 10 10);
my @si_opt = (
strategy => 'QuadTree',
storage => 'Memory',
limit_x_low => $limits[0],
limit_y_low => $limits[1],
limit_x_up => $limits[2],
limit_y_up => $limits[3],
bucket_size => $bucks,
);
my @si_opt_redis = (
strategy => 'QuadTree',
storage => 'Redis',
limit_x_low => $limits[0],
limit_y_low => $limits[1],
limit_x_up => $limits[2],
limit_y_up => $limits[3],
bucket_size => $bucks,
redis => $redis_cfg,
);
my @si_opt_m = @si_opt;
$si_opt_m[1] = 'MedianQuadTree';
my @qt_opt = (
-xmin => $limits[0],
-ymin => $limits[1],
-xmax => $limits[2],
-ymax => $limits[3],
-depth => $depth,
);
if ($redis_cfg) {
my $idx = Algorithm::SpatialIndex->new(@si_opt_redis);
$idx->storage->remove_all;
}
my $xrange = $limits[2]-$limits[0];
my $yrange = $limits[3]-$limits[1];
my $concx = $limits[0] + $xrange/3;
my $concy = $limits[1] + $yrange*2/3;
( run in 1.278 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )