Update Ukrainian translation
[gegl.git] / perf / test-samplers.c
blob060771ba26a9a42799982445737a846b50a61fe0
1 #include "test-common.h"
3 #define BPP 16
4 #define SAMPLES 250000
6 /* gegl_buffer_sample() should not be used in performance-critical code. the
7 * corresponding tests take a long time to finish, and are disabled by default.
8 * uncomment this line to enable them.
9 */
10 /* #define TEST_BUFFER_SAMPLE */
12 gint
13 main (gint argc,
14 gchar **argv)
16 GeglBuffer *buffer;
17 GeglRectangle bound = {0, 0, 4024, 4024};
18 const Babl *format, *format2;
19 gchar *buf;
20 gint i;
22 gegl_init (NULL, NULL);
23 format = babl_format ("RGBA float");
24 format2 = babl_format ("R'G'B'A float");
25 buffer = gegl_buffer_new (&bound, format);
26 buf = g_malloc0 (bound.width * bound.height * BPP);
28 /* pre-initialize */
29 gegl_buffer_set (buffer, &bound, 0, NULL, buf, GEGL_AUTO_ROWSTRIDE);
31 format = babl_format ("RGBA float");
34 gint rands[SAMPLES*2];
36 for (i = 0; i < SAMPLES; i ++)
38 rands[i*2] = rand()%1000;
39 rands[i*2+1] = rand()%1000;
40 rands[i*2] = i / 1000;
41 rands[i*2+1] = i % 1000;
44 test_start ();
45 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
47 int j;
48 float px[4] = {0.2, 0.4, 0.1, 0.5};
49 test_start_iter();
50 for (j = 0; j < SAMPLES; j ++)
52 int x = rands[j*2];
53 int y = rands[j*2+1];
54 GeglRectangle rect = {x, y, 1, 1};
55 gegl_buffer_get (buffer, &rect, 1.0, format2, (void*)&px[0],
56 GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
58 test_end_iter();
60 test_end ("gegl_buffer_get 1x1 + babl", 1.0 * SAMPLES * ITERATIONS * BPP);
62 test_start ();
63 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
65 int j;
66 float px[4] = {0.2, 0.4, 0.1, 0.5};
67 test_start_iter();
68 for (j = 0; j < SAMPLES; j ++)
70 int x = rands[j*2];
71 int y = rands[j*2+1];
72 gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
73 GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
75 test_end_iter();
77 test_end ("gegl_buffer_sample nearest", 1.0 * SAMPLES * ITERATIONS * BPP);
79 test_start ();
80 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
82 int j;
83 float px[4] = {0.2, 0.4, 0.1, 0.5};
84 test_start_iter();
85 for (j = 0; j < SAMPLES; j ++)
87 int x = rands[j*2];
88 int y = rands[j*2+1];
89 gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
90 GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
92 test_end_iter();
94 test_end ("gegl_buffer_sample near+ba", 1.0 * SAMPLES * ITERATIONS * BPP);
96 test_start ();
97 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
99 int j;
100 float px[4] = {0.2, 0.4, 0.1, 0.5};
101 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
102 GEGL_SAMPLER_NEAREST);
103 test_start_iter();
105 for (j = 0; j < SAMPLES; j ++)
107 int x = rands[j*2];
108 int y = rands[j*2+1];
109 gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
112 test_end_iter();
113 g_object_unref (sampler);
115 test_end ("gegl_sampler_get nearest", 1.0 * SAMPLES * ITERATIONS * BPP);
117 test_start ();
118 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
120 int j;
121 float px[4] = {0.2, 0.4, 0.1, 0.5};
122 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
123 GEGL_SAMPLER_NEAREST);
124 GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
126 test_start_iter();
127 for (j = 0; j < SAMPLES; j ++)
129 int x = rands[j*2];
130 int y = rands[j*2+1];
131 sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
133 test_end_iter();
135 g_object_unref (sampler);
137 test_end ("sampler_get_fun nearest", 1.0 * SAMPLES * ITERATIONS * BPP);
140 test_start ();
141 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
143 int j;
144 float px[4] = {0.2, 0.4, 0.1, 0.5};
145 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format2,
146 GEGL_SAMPLER_NEAREST);
147 GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
149 test_start_iter();
150 for (j = 0; j < SAMPLES; j ++)
152 int x = rands[j*2];
153 int y = rands[j*2+1];
154 sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
156 test_end_iter();
158 g_object_unref (sampler);
160 test_end ("sampler_get_fun nearest+babl", 1.0 * SAMPLES * ITERATIONS * BPP);
163 #ifdef TEST_BUFFER_SAMPLE
164 test_start ();
165 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
167 int j;
168 float px[4] = {0.2, 0.4, 0.1, 0.5};
169 test_start_iter();
170 for (j = 0; j < SAMPLES; j ++)
172 int x = rands[j*2];
173 int y = rands[j*2+1];
174 gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
175 GEGL_SAMPLER_LINEAR, GEGL_ABYSS_NONE);
177 test_end_iter();
179 test_end ("gegl_buffer_sample linear", 1.0 * SAMPLES * ITERATIONS * BPP);
180 #endif
182 test_start ();
183 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
185 int j;
186 float px[4] = {0.2, 0.4, 0.1, 0.5};
187 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
188 GEGL_SAMPLER_LINEAR);
190 test_start_iter();
191 for (j = 0; j < SAMPLES; j ++)
193 int x = rands[j*2];
194 int y = rands[j*2+1];
195 gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
197 test_end_iter();
199 g_object_unref (sampler);
201 test_end ("gegl_sampler_get linear", 1.0 * SAMPLES * ITERATIONS * BPP);
203 test_start ();
204 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
206 int j;
207 float px[4] = {0.2, 0.4, 0.1, 0.5};
208 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
209 GEGL_SAMPLER_LINEAR);
210 GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
212 test_start_iter();
213 for (j = 0; j < SAMPLES; j ++)
215 int x = rands[j*2];
216 int y = rands[j*2+1];
217 sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
219 test_end_iter();
221 g_object_unref (sampler);
223 test_end ("sampler_get_fun linear", 1.0 * SAMPLES * ITERATIONS * BPP);
225 #ifdef TEST_BUFFER_SAMPLE
226 test_start ();
227 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
229 int j;
230 float px[4] = {0.2, 0.4, 0.1, 0.5};
231 test_start_iter();
232 for (j = 0; j < SAMPLES; j ++)
234 int x = rands[j*2];
235 int y = rands[j*2+1];
236 gegl_buffer_sample (buffer, x, y, NULL, (void*)&px[0], format,
237 GEGL_SAMPLER_CUBIC, GEGL_ABYSS_NONE);
239 test_end_iter();
241 test_end ("gegl_buffer_sample cubic", 1.0 * SAMPLES * ITERATIONS * BPP);
242 #endif
244 test_start ();
245 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
247 int j;
248 float px[4] = {0.2, 0.4, 0.1, 0.5};
249 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
250 GEGL_SAMPLER_CUBIC);
252 test_start_iter();
253 for (j = 0; j < SAMPLES; j ++)
255 int x = rands[j*2];
256 int y = rands[j*2+1];
257 gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
259 test_end_iter();
261 g_object_unref (sampler);
263 test_end ("gegl_sampler_get cubic", 1.0 * SAMPLES * ITERATIONS * BPP);
265 test_start ();
266 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
268 int j;
269 float px[4] = {0.2, 0.4, 0.1, 0.5};
270 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
271 GEGL_SAMPLER_CUBIC);
272 GeglSamplerGetFun sampler_get_fun = gegl_sampler_get_fun (sampler);
274 test_start_iter();
275 for (j = 0; j < SAMPLES; j ++)
277 int x = rands[j*2];
278 int y = rands[j*2+1];
279 sampler_get_fun (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
281 test_end_iter();
283 g_object_unref (sampler);
285 test_end ("sampler_get_fun cubic", 1.0 * SAMPLES * ITERATIONS * BPP);
287 test_start ();
288 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
290 int j;
291 float px[4] = {0.2, 0.4, 0.1, 0.5};
292 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
293 GEGL_SAMPLER_NOHALO);
295 test_start_iter();
296 for (j = 0; j < SAMPLES; j ++)
298 int x = rands[j*2];
299 int y = rands[j*2+1];
300 gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
302 test_end_iter();
304 g_object_unref (sampler);
306 test_end ("gegl_sampler_get nohalo", 1.0 * SAMPLES * ITERATIONS * BPP);
308 test_start ();
309 for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
311 int j;
312 float px[4] = {0.2, 0.4, 0.1, 0.5};
313 GeglSampler *sampler = gegl_buffer_sampler_new (buffer, format,
314 GEGL_SAMPLER_LOHALO);
316 test_start_iter();
317 for (j = 0; j < SAMPLES; j ++)
319 int x = rands[j*2];
320 int y = rands[j*2+1];
321 gegl_sampler_get (sampler, x, y, NULL, (void*)&px[0], GEGL_ABYSS_NONE);
323 test_end_iter();
325 g_object_unref (sampler);
327 test_end ("gegl_sampler_get lohalo", 1.0 * SAMPLES * ITERATIONS * BPP);
333 g_free (buf);
334 g_object_unref (buffer);
336 return 0;