From: Tony Cook Date: Sat, 23 Oct 2010 23:57:18 +0000 (+0000) Subject: convert benchmark X-Git-Tag: Imager-0.79~22 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/33217035944c6653c24f067a7f52871c8bced141 convert benchmark --- diff --git a/bench/convert.pl b/bench/convert.pl new file mode 100644 index 00000000..71e51f53 --- /dev/null +++ b/bench/convert.pl @@ -0,0 +1,56 @@ +#!perl -w +use strict; +use Benchmark qw(:hireswallclock countit); +use Imager; + +my $im = Imager->new(xsize => 1000, ysize => 1000); +my $ima = $im->convert(preset => "addalpha"); +my $im_pal = Imager->new(xsize => 1000, ysize => 1000, type => "paletted"); +my @colors = map Imager::Color->new($_), qw/red green blue white black/; +$im_pal->addcolors(colors => \@colors); +my $color = $colors[0]; +my $other = Imager::Color->new("pink"); + +countthese + (5, + { + gray => sub { + my $temp = $im->convert(preset => "grey") + for 1 .. 10; + }, + green => sub { + my $temp = $im->convert(preset => "green") + for 1 .. 10; + }, + addalpha => sub { + my $temp = $im->convert(preset => "addalpha") + for 1 .. 10; + }, + noalpha => sub { + my $temp = $ima->convert(preset => "noalpha") + for 1 .. 10; + }, + } + ); + +$im_pal->type eq "paletted" or die "Not paletted anymore"; + +sub countthese { + my ($limit, $what) = @_; + + for my $key (sort keys %$what) { + my $bench = countit($limit, $what->{$key}); + printf "$key: %.1f /s (%f / iter)\n", $bench->iters / $bench->cpu_p, + $bench->cpu_p / $bench->iters; + } +} + +__END__ + +Original: + +addalpha: 0.9 /s (1.082000 / iter) +gray: 3.3 /s (0.303529 / iter) +green: 4.1 /s (0.244286 / iter) +noalpha: 1.1 /s (0.876667 / iter) +