Algorithm-SpatialIndex

 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::QuadTree;
use Benchmark qw(cmpthese timethese);

# ordered or random or concentrated_random
#my $item_mode = 'ordered';
#my $item_mode = 'random';
my $item_mode = 'concentrated_random';

my $use_dbi = 0;
if ($use_dbi) {
  eval "use DBI; use DBD::SQLite;";
  unlink 't.sqlite';
  $use_dbi = DBI->connect("dbi:SQLite:dbname=t.sqlite", "", "");
}
my $use_median_qtree = eval {
  use Algorithm::SpatialIndex::Strategy::MedianQuadTree;
  1;
};

my $bucks = 100;
my $scale = 15;
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_dbi = (
  strategy => 'QuadTree',
  storage  => 'DBI',
  limit_x_low => $limits[0],
  limit_y_low => $limits[1],
  limit_x_up  => $limits[2],
  limit_y_up  => $limits[3],
  bucket_size => $bucks,
  dbh_rw => $use_dbi,
);
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,
);

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;
my $conc_rx = $xrange/30;
my $conc_ry = $xrange/20;



( run in 0.915 second using v1.01-cache-2.11-cpan-62a16548d74 )