add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / bench / box.pl
CommitLineData
4dd88895
TC
1#!perl -w
2use strict;
3use Benchmark qw(:hireswallclock countit);
4use Imager;
5
6my $im = Imager->new(xsize => 1000, ysize => 1000);
7my $im_pal = Imager->new(xsize => 1000, ysize => 1000, type => "paletted");
8my @colors = map Imager::Color->new($_), qw/red green blue white black/;
9$im_pal->addcolors(colors => \@colors);
10my $color = $colors[0];
11my $other = Imager::Color->new("pink");
12
13countthese
14 (5,
15 {
16 box0010 => sub {
17 $im->box(xmax => 10, ymax => 10, color => $other)
18 for 1 .. 100;
19 },
20 box0010c => sub {
21 $im->box(xmax => 10, ymax => 10, color => "pink")
22 for 1 .. 100;
23 },
24 box0010d => sub {
25 $im->box(xmax => 10, ymax => 10)
26 for 1 .. 100;
27 },
28 box0100 => sub {
29 $im->box(xmax => 100, ymax => 100, color => $other)
30 for 1 .. 100;
31 },
32 box0500 => sub {
33 $im->box(xmax => 500, ymax => 500, color => $other)
34 for 1 .. 100;
35 },
36 box1000 => sub {
37 $im->box(color => $other)
38 for 1 .. 100;
39 },
40 palbox0010 => sub {
41 $im_pal->box(xmax => 10, ymax => 10, color => $color)
42 for 1 .. 100;
43 },
44 palbox0100 => sub {
45 $im_pal->box(xmax => 100, ymax => 100, color => $color)
46 for 1 .. 100;
47 },
48 palbox0500 => sub {
49 $im_pal->box(xmax => 500, ymax => 500, color => $color)
50 for 1 .. 100;
51 },
52 palbox1000 => sub {
53 $im_pal->box(color => $color)
54 for 1 .. 100;
55 },
56
57 fbox0010 => sub {
58 $im->box(xmax => 10, ymax => 10, filled => 1, color => $other)
59 for 1 .. 100;
60 },
61 fbox0010c => sub {
62 $im->box(xmax => 10, ymax => 10, filled => 1, color => "pink")
63 for 1 .. 100;
64 },
65 fbox0010d => sub {
66 $im->box(xmax => 10, ymax => 10, filled => 1)
67 for 1 .. 100;
68 },
69 fbox0100 => sub {
70 $im->box(xmax => 100, ymax => 100, filled => 1, color => $other)
71 for 1 .. 100;
72 },
73 fbox0500 => sub {
74 $im->box(xmax => 500, ymax => 500, filled => 1, color => $other)
75 for 1 .. 100;
76 },
77 fbox1000 => sub {
78 $im->box(color => $other, filled => 1)
79 for 1 .. 100;
80 },
81 fpalbox0010 => sub {
82 $im_pal->box(xmax => 10, ymax => 10, filled => 1, color => $color)
83 for 1 .. 100;
84 },
85 fpalbox0100 => sub {
86 $im_pal->box(xmax => 100, ymax => 100, filled => 1, color => $color)
87 for 1 .. 100;
88 },
89 fpalbox0500 => sub {
90 $im_pal->box(xmax => 500, ymax => 500, filled => 1, color => $color)
91 for 1 .. 100;
92 },
93 fpalbox1000 => sub {
94 $im_pal->box(filled => 1, color => $color)
95 for 1 .. 100;
96 },
97 }
98 );
99
100$im_pal->type eq "paletted" or die "Not paletted anymore";
101
102sub countthese {
103 my ($limit, $what) = @_;
104
105 for my $key (sort keys %$what) {
106 my $bench = countit($limit, $what->{$key});
107 printf "$key: %.1f /s (%f / iter)\n", $bench->iters / $bench->cpu_p,
108 $bench->cpu_p / $bench->iters;
109 }
110}
111
112__END__
113
114Original:
115
116box0010: 397.7 /s (0.002514 / iter)
117box0010c: 3.3 /s (0.305882 / iter)
118box0010d: 399.6 /s (0.002502 / iter)
119box0100: 329.5 /s (0.003035 / iter)
120box0500: 191.5 /s (0.005223 / iter)
121box1000: 130.6 /s (0.007657 / iter)
122fbox0010: 372.3 /s (0.002686 / iter)
123fbox0010c: 3.3 /s (0.300588 / iter)
124fbox0010d: 383.2 /s (0.002610 / iter)
125fbox0100: 63.8 /s (0.015685 / iter)
126fbox0500: 2.8 /s (0.361429 / iter)
127fbox1000: 0.7 /s (1.435000 / iter)
128fpalbox0010: 370.9 /s (0.002696 / iter)
129fpalbox0100: 53.2 /s (0.018799 / iter)
130fpalbox0500: 2.4 /s (0.413077 / iter)
131fpalbox1000: 0.6 /s (1.700000 / iter)
132palbox0010: 390.2 /s (0.002563 / iter)
133palbox0100: 316.9 /s (0.003155 / iter)
134palbox0500: 171.8 /s (0.005820 / iter)
135palbox1000: 115.0 /s (0.008694 / iter)
136
137Re-work sub box():
138
139box0010: 786.0 /s (0.001272 / iter)
140box0010c: 3.3 /s (0.300000 / iter)
141box0010d: 463.7 /s (0.002157 / iter)
142box0100: 556.6 /s (0.001797 / iter)
143box0500: 254.4 /s (0.003930 / iter)
144box1000: 154.8 /s (0.006460 / iter)
145fbox0010: 700.9 /s (0.001427 / iter)
146fbox0010c: 3.3 /s (0.302353 / iter)
147fbox0010d: 437.0 /s (0.002288 / iter)
148fbox0100: 69.2 /s (0.014444 / iter)
149fbox0500: 2.8 /s (0.357143 / iter)
150fbox1000: 0.7 /s (1.437500 / iter)
151fpalbox0010: 673.5 /s (0.001485 / iter)
152fpalbox0100: 46.8 /s (0.021377 / iter)
153fpalbox0500: 2.0 /s (0.505000 / iter)
154fpalbox1000: 0.5 /s (2.140000 / iter)
155palbox0010: 740.9 /s (0.001350 / iter)
156palbox0100: 473.2 /s (0.002113 / iter)
157palbox0500: 186.2 /s (0.005371 / iter)
158palbox1000: 109.1 /s (0.009167 / iter)
3b000586
TC
159
160re-work i_box_filled():
161
162box0010: 783.0 /s (0.001277 / iter)
163box0010c: 3.3 /s (0.300588 / iter)
164box0010d: 463.7 /s (0.002157 / iter)
165box0100: 548.2 /s (0.001824 / iter)
166box0500: 250.2 /s (0.003997 / iter)
167box1000: 155.1 /s (0.006448 / iter)
168fbox0010: 743.7 /s (0.001345 / iter)
169fbox0010c: 3.3 /s (0.302941 / iter)
170fbox0010d: 448.3 /s (0.002231 / iter)
171fbox0100: 147.8 /s (0.006765 / iter)
172fbox0500: 7.6 /s (0.132308 / iter)
173fbox1000: 1.9 /s (0.521000 / iter)
174fpalbox0010: 784.9 /s (0.001274 / iter)
175fpalbox0100: 424.7 /s (0.002355 / iter)
176fpalbox0500: 42.6 /s (0.023496 / iter)
177fpalbox1000: 11.4 /s (0.087966 / iter)
178palbox0010: 778.8 /s (0.001284 / iter)
179palbox0100: 541.5 /s (0.001847 / iter)
180palbox0500: 238.0 /s (0.004203 / iter)
181palbox1000: 141.1 /s (0.007088 / iter)
182
183optimize getwidth/getheight:
184
185box0010: 832.5 /s (0.001201 / iter)
186box0010c: 3.4 /s (0.297647 / iter)
187box0010d: 491.3 /s (0.002035 / iter)
188box0100: 594.7 /s (0.001682 / iter)
189box0500: 259.1 /s (0.003859 / iter)
190box1000: 158.5 /s (0.006310 / iter)
191fbox0010: 798.1 /s (0.001253 / iter)
192fbox0010c: 3.3 /s (0.300588 / iter)
193fbox0010d: 477.7 /s (0.002093 / iter)
194fbox0100: 148.5 /s (0.006735 / iter)
195fbox0500: 7.5 /s (0.134103 / iter)
196fbox1000: 1.9 /s (0.530000 / iter)
197fpalbox0010: 829.0 /s (0.001206 / iter)
198fpalbox0100: 444.1 /s (0.002252 / iter)
199fpalbox0500: 43.0 /s (0.023260 / iter)
200fpalbox1000: 11.5 /s (0.087333 / iter)
201palbox0010: 826.0 /s (0.001211 / iter)
202palbox0100: 553.2 /s (0.001808 / iter)
203palbox0500: 242.7 /s (0.004119 / iter)
204palbox1000: 144.4 /s (0.006923 / iter)
205
206pull stuff out of the hash fast:
207
208box0010: 1332.0 /s (0.000751 / iter)
209box0010c: 3.4 /s (0.295882 / iter)
210box0010d: 646.6 /s (0.001546 / iter)
211box0100: 805.3 /s (0.001242 / iter)
212box0500: 293.1 /s (0.003412 / iter)
213box1000: 161.7 /s (0.006183 / iter)
214fbox0010: 1215.2 /s (0.000823 / iter)
215fbox0010c: 3.4 /s (0.295294 / iter)
216fbox0010d: 600.9 /s (0.001664 / iter)
217fbox0100: 160.2 /s (0.006241 / iter)
218fbox0500: 7.6 /s (0.131250 / iter)
219fbox1000: 1.9 /s (0.519000 / iter)
220fpalbox0010: 1295.2 /s (0.000772 / iter)
221fpalbox0100: 547.2 /s (0.001828 / iter)
222fpalbox0500: 43.8 /s (0.022845 / iter)
223fpalbox1000: 11.5 /s (0.087333 / iter)
224palbox0010: 1314.1 /s (0.000761 / iter)
225palbox0100: 752.2 /s (0.001330 / iter)
226palbox0500: 269.4 /s (0.003712 / iter)
227palbox1000: 145.3 /s (0.006884 / iter)
813d4d0a
TC
228
229make _is_color_object xs
230
231box0010: 1359.4 /s (0.000736 / iter)
232box0010c: 3.4 /s (0.294118 / iter)
233box0010d: 635.6 /s (0.001573 / iter)
234box0100: 818.6 /s (0.001222 / iter)
235box0500: 294.3 /s (0.003398 / iter)
236box1000: 162.9 /s (0.006140 / iter)
237fbox0010: 1230.8 /s (0.000813 / iter)
238fbox0010c: 3.2 /s (0.313125 / iter)
239fbox0010d: 608.7 /s (0.001643 / iter)
240fbox0100: 158.5 /s (0.006308 / iter)
241fbox0500: 7.5 /s (0.134103 / iter)
242fbox1000: 1.9 /s (0.530000 / iter)
243fpalbox0010: 1328.8 /s (0.000753 / iter)
244fpalbox0100: 553.2 /s (0.001808 / iter)
245fpalbox0500: 43.5 /s (0.022974 / iter)
246fpalbox1000: 11.4 /s (0.087627 / iter)
247palbox0010: 1344.8 /s (0.000744 / iter)
248palbox0100: 783.0 /s (0.001277 / iter)
249palbox0500: 274.5 /s (0.003643 / iter)
250palbox1000: 147.9 /s (0.006761 / iter)
fe441a3a
TC
251
252fix x color table caching check:
253
254box0010: 1376.1 /s (0.000727 / iter)
255box0010c: 257.9 /s (0.003877 / iter)
256box0010d: 642.4 /s (0.001557 / iter)
257box0100: 820.2 /s (0.001219 / iter)
258box0500: 294.0 /s (0.003402 / iter)
259box1000: 163.2 /s (0.006129 / iter)
260fbox0010: 1228.5 /s (0.000814 / iter)
261fbox0010c: 252.8 /s (0.003956 / iter)
262fbox0010d: 617.8 /s (0.001619 / iter)
263fbox0100: 158.5 /s (0.006308 / iter)
264fbox0500: 7.5 /s (0.133846 / iter)
265fbox1000: 1.9 /s (0.530000 / iter)
266fpalbox0010: 1343.4 /s (0.000744 / iter)
267fpalbox0100: 557.3 /s (0.001794 / iter)
268fpalbox0500: 43.9 /s (0.022759 / iter)
269fpalbox1000: 11.5 /s (0.087000 / iter)
270palbox0010: 1365.3 /s (0.000732 / iter)
271palbox0100: 787.7 /s (0.001270 / iter)
272palbox0500: 275.6 /s (0.003629 / iter)
273palbox1000: 148.4 /s (0.006739 / iter)