#! perl -slw
use strict;
use GD;
my $map = GD::Image->new( 5000, 5000, 1 )
or die $!;
my $index = 0;
my $bg = $map->colorAllocate( 0, 0, 0 );
$map->filledRectangle( 0, 0, 4999, 4999, $bg );
for my $y ( map{ $_ *10 +5 } 0 .. 499 ) {
for my $x ( map{ $_ * 10 + 5 } 0 .. 499 ) {
my $color = $map->colorAllocate( unpack 'xCCC', pack 'N', $index += 64 );
# print $color;
$map->filledEllipse( $x, $y, 10, 10, $color );
}
}
open IMG, '>:raw', '569929.png' or die $!;
print IMG $map->png;
close IMG;
####
#! perl -slw
use strict;
open POINTS, '>', '569929.points' or die $!;
printf POINTS "%d:%d\n", int( rand 5000 ), int( rand 5000 ) for 1 .. 5.25e6;
close POINTS;
####
#! perl -slw
use strict;
use Benchmark::Timer;
use GD;
my $map = GD::Image->newFromPng( '569929.png', 1 );
open POINTS, '<', '569929.points' or die $!;
my $T = new Benchmark::Timer;
$T->start( '5.25e6 points in 2.5e5 polys' );
while( ) {
chomp;
my( $x, $y ) = split ':';
my $poly = $map->getPixel($x, $y );
# printf "Point ( %4.4d, %4.4d ) found in poly: %d\n", $x, $y, $poly / 64;
}
$T->stop( '5.25e6 points in 2.5e5 polys' );
$T->report;
close POINTS;
####
c:\test>569929-b
1 trial of 5,25e6 points in 2.5e5 polys (33.094s total)
c:\test>569929-b
1 trial of 5.25e6 points in 2.5e5 polys (36.656s total)
c:\test>569929-b
1 trial of 5.25e6 points in 2.5e5 polys (33.250s total)
c:\test>569929-b
1 trial of 5.25e6 points in 2.5e5 polys (35.094s total)
c:\test>569929-b
1 trial of 5.25e6 points in 2.5e5 polys (33.734s total)