]> git.imager.perl.org - imager.git/commitdiff
convert benchmark
authorTony Cook <tony@develop=help.com>
Sat, 23 Oct 2010 23:57:18 +0000 (23:57 +0000)
committerTony Cook <tony@develop=help.com>
Sat, 23 Oct 2010 23:57:18 +0000 (23:57 +0000)
bench/convert.pl [new file with mode: 0644]

diff --git a/bench/convert.pl b/bench/convert.pl
new file mode 100644 (file)
index 0000000..71e51f5
--- /dev/null
@@ -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)
+