Geo-Index
view release on metacpan or search on metacpan
examples/benchmark.pl view on Meta::CPAN
print " Point area: Points distributed over entire planet\n";
print " ".commify(int($planet_area_square_km))." square km\n";
my $points_per_square_km = commify($config{size} / $planet_area_square_km);
print " $points_per_square_km points per square km\n";
my $min_tile_area = $planet_area / ( 2**($config{levels} - 1) );
my $min_tile_points = $config{size} / $planet_area * $min_tile_area;
print " $min_tile_points per tile at full index depth\n";
}
}
# Pretty-print a number with commas between thousands
# From the Perl Cookbook
sub commify($) {
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}
#.Pretty print a number as a number of bytes and as a shorthand (e.g. MB)
sub PrettyPrint($) {
my ($n) = @_;
my $v = $n;
my $u = 0;
while ($v >= 1024) {
$v /= 1024;
$u++;
last if ($u == 4);
}
$v = ( $v == int $v ) ? $v : sprintf("%.2f", $v);
$u = ($u == 0) ? 'B'
: ($u == 1) ? 'kB'
: ($u == 2) ? 'MB'
: ($u == 3) ? 'GB'
: 'TB';
return sprintf("%14s B ( %7.2f %s )", commify($n), $v, $u );
}
# Run a block of code multiple times for at least the specified number of seconds
sub benchmark_code($$) {
my ($MIN_TEST_SECONDS, $_code) = @_;
my $count = 0;
my $t0 = Time::HiRes::time();
my $t_end = $t0 + $MIN_TEST_SECONDS;
my $t1;
do {
&$_code();
$t1 = Time::HiRes::time();
$count++;
} until ($t1 >= $t_end );
my $duration = $t1 - $t0;
print "$count iterations over $duration seconds, ".($count/$duration)." iterations per second\n";
return [ $count, $duration ];
}
( run in 0.484 second using v1.01-cache-2.11-cpan-71847e10f99 )