add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / bench / convert.pl
CommitLineData
33217035
TC
1#!perl -w
2use strict;
3use Benchmark qw(:hireswallclock countit);
4use Imager;
5
6my $im = Imager->new(xsize => 1000, ysize => 1000);
7my $ima = $im->convert(preset => "addalpha");
8my $im_pal = Imager->new(xsize => 1000, ysize => 1000, type => "paletted");
9my @colors = map Imager::Color->new($_), qw/red green blue white black/;
10$im_pal->addcolors(colors => \@colors);
11my $color = $colors[0];
12my $other = Imager::Color->new("pink");
13
14countthese
15 (5,
16 {
17 gray => sub {
18 my $temp = $im->convert(preset => "grey")
19 for 1 .. 10;
20 },
21 green => sub {
22 my $temp = $im->convert(preset => "green")
23 for 1 .. 10;
24 },
25 addalpha => sub {
26 my $temp = $im->convert(preset => "addalpha")
27 for 1 .. 10;
28 },
29 noalpha => sub {
30 my $temp = $ima->convert(preset => "noalpha")
31 for 1 .. 10;
32 },
33 }
34 );
35
36$im_pal->type eq "paletted" or die "Not paletted anymore";
37
38sub countthese {
39 my ($limit, $what) = @_;
40
41 for my $key (sort keys %$what) {
42 my $bench = countit($limit, $what->{$key});
43 printf "$key: %.1f /s (%f / iter)\n", $bench->iters / $bench->cpu_p,
44 $bench->cpu_p / $bench->iters;
45 }
46}
47
48__END__
49
50Original:
51
2a2c791f
TC
52addalpha: 1.3 /s (0.797143 / iter)
53gray: 4.3 /s (0.233636 / iter)
54green: 4.9 /s (0.205600 / iter)
55noalpha: 1.6 /s (0.608889 / iter)
56
57convert_via_copy:
58
59addalpha: 4.9 /s (0.205600 / iter)
60gray: 4.2 /s (0.235909 / iter)
61green: 8.6 /s (0.115682 / iter)
62noalpha: 5.4 /s (0.185556 / iter)
33217035 63