add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / bench / circlef.pl
CommitLineData
1bc6916b
TC
1#!perl -w
2use strict;
3use Benchmark qw(:hireswallclock countit);
4use Imager;
5use Imager::Fill;
6
7#Imager->open_log(log => "circlef.log", loglevel => 2);
8
9print $INC{"Imager.pm"}, "\n";
10
11my $im = Imager->new(xsize => 1000, ysize => 1000);
12my $im_pal = Imager->new(xsize => 1000, ysize => 1000, type => "paletted");
13my @colors = map Imager::Color->new($_), qw/red green blue white black/;
14$im_pal->addcolors(colors => \@colors);
15my $color = $colors[0];
16my $other = Imager::Color->new("pink");
17my $fill = Imager::Fill->new(solid => "#ffff0080", combine => "normal");
18
19countthese
20 (5,
21 {
22 tiny_c_aa => sub {
23 $im->circle(color => $color, r => 2, x => 20, y => 75, aa => 1)
24 for 1 .. 100;
25 },
26 small_c_aa => sub {
27 $im->circle(color => $color, r => 10, x => 20, y => 25, aa => 1)
28 for 1 .. 100;
29 },
30 medium_c_aa => sub {
31 $im->circle(color => $color, r => 60, x => 70, y => 80, aa => 1)
32 for 1 .. 100;
33 },
34 large_c_aa => sub {
35 $im->circle(color => $color, r => 400, x => 550, y => 580, aa => 1)
36 for 1 .. 100;
37 },
38
39 tiny_fill_aa => sub {
40 $im->circle(fill => $fill, r => 2, x => 20, y => 75, aa => 1)
41 for 1 .. 100;
42 },
43 small_fill_aa => sub {
44 $im->circle(fill => $fill, r => 10, x => 20, y => 25, aa => 1)
45 for 1 .. 100;
46 },
47 medium_fill_aa => sub {
48 $im->circle(fill => $fill, r => 60, x => 70, y => 80, aa => 1)
49 for 1 .. 100;
50 },
51 large_fill_aa => sub {
52 $im->circle(fill => $fill, r => 400, x => 550, y => 580, aa => 1)
53 for 1 .. 100;
54 },
55 }
56 );
57
58#$im_pal->type eq "paletted" or die "Not paletted anymore";
59
60sub countthese {
61 my ($limit, $what) = @_;
62
63 for my $key (sort keys %$what) {
64 my $bench = countit($limit, $what->{$key});
65 printf "$key: %.1f /s (%f / iter)\n", $bench->iters / $bench->cpu_p,
66 $bench->cpu_p / $bench->iters;
67 }
68}
69
70__END__
71
72Original:
73
74large_c_aa: 0.1 /s (13.110000 / iter)
75large_fill_aa: 0.5 /s (2.026667 / iter)
76medium_c_aa: 0.7 /s (1.402500 / iter)
77medium_fill_aa: 1.9 /s (0.513000 / iter)
78small_c_aa: 4.3 /s (0.230909 / iter)
79small_fill_aa: 9.9 /s (0.100962 / iter)
80tiny_c_aa: 17.4 /s (0.057444 / iter)
81tiny_fill_aa: 25.7 /s (0.038947 / iter)
82
83use a better algorithm for i_circle_aa() circle calculation:
84
85large_c_aa: 1.3 /s (0.797143 / iter)
86large_fill_aa: 0.5 /s (2.013333 / iter)
87medium_c_aa: 32.2 /s (0.031012 / iter)
88medium_fill_aa: 1.9 /s (0.523000 / iter)
89small_c_aa: 166.8 /s (0.005993 / iter)
90small_fill_aa: 9.9 /s (0.101373 / iter)
91tiny_c_aa: 252.1 /s (0.003967 / iter)
92tiny_fill_aa: 25.7 /s (0.038897 / iter)
bf18ef3a
TC
93
94add i_circle_aa_fill() and use it:
95
96large_c_aa: 1.1 /s (0.948333 / iter)
97large_fill_aa: 0.7 /s (1.500000 / iter)
98medium_c_aa: 31.0 /s (0.032303 / iter)
99medium_fill_aa: 22.1 /s (0.045175 / iter)
100small_c_aa: 223.1 /s (0.004482 / iter)
101small_fill_aa: 218.1 /s (0.004585 / iter)
102tiny_c_aa: 394.4 /s (0.002536 / iter)
103tiny_fill_aa: 437.8 /s (0.002284 / iter)
104