8 struct timeval start_time;
10 void start_timing (void)
12 gettimeofday (&start_time, NULL);
16 stop_timing (const char *test, int iterations, int bytes)
18 struct timeval stop_time;
21 gettimeofday (&stop_time, NULL);
22 if (stop_time.tv_usec < start_time.tv_usec)
24 stop_time.tv_usec += 1000000;
25 stop_time.tv_sec -= 1;
28 msecs = (stop_time.tv_sec - start_time.tv_sec) * 1000. +
29 (stop_time.tv_usec - start_time.tv_usec) / 1000.;
31 printf("%s%d\t%.1f\t\t%.2f\t\t%.2f\n",
32 test, iterations, msecs, msecs / iterations, ((double)bytes * iterations) / (1000*msecs));
34 return ((double)bytes * iterations) / (1000*msecs);
38 init_array (double times[3][3][4])
49 dump_array (double times[3][3][4])
53 printf(" 3\t4\t4a\n");
74 printf("%6.2f %6.2f %6.2f",
75 times[i][0][j], times[i][1][j], times[i][2][j]);
79 case ART_FILTER_NEAREST:
80 printf (" NEAREST\n");
82 case ART_FILTER_TILES:
85 case ART_FILTER_BILINEAR:
86 printf (" BILINEAR\n");
88 case ART_FILTER_HYPER:
99 int main (int argc, char **argv)
101 int src_width, src_height, dest_width, dest_height;
102 char *src_buf, *dest_buf;
103 int src_index, dest_index;
105 double scale_times[3][3][4];
106 double composite_times[3][3][4];
107 double composite_color_times[3][3][4];
111 src_width = atoi(argv[1]);
112 src_height = atoi(argv[2]);
113 dest_width = atoi(argv[3]);
114 dest_height = atoi(argv[4]);
125 fprintf (stderr, "Usage: scale [src_width src_height dest_width dest_height]\n");
130 printf ("Scaling from (%d, %d) to (%d, %d)\n\n", src_width, src_height, dest_width, dest_height);
132 for (src_index = 0; src_index < 3; src_index++)
133 for (dest_index = 0; dest_index < 3; dest_index++)
135 int src_channels = (src_index == 0) ? 3 : 4;
136 int src_has_alpha = (src_index == 2);
137 int dest_channels = (dest_index == 0) ? 3 : 4;
138 int dest_has_alpha = (dest_index == 2);
140 int src_rowstride = (src_channels*src_width + 3) & ~3;
141 int dest_rowstride = (dest_channels *dest_width + 3) & ~3;
145 src_buf = malloc(src_rowstride * src_height);
146 memset (src_buf, 0x80, src_rowstride * src_height);
148 dest_buf = malloc(dest_rowstride * dest_height);
149 memset (dest_buf, 0x80, dest_rowstride * dest_height);
151 for (filter_level = ART_FILTER_NEAREST ; filter_level <= ART_FILTER_HYPER; filter_level++)
153 printf ("src_channels = %d (%s); dest_channels = %d (%s); filter_level=",
154 src_channels, src_has_alpha ? "alpha" : "no alpha",
155 dest_channels, dest_has_alpha ? "alpha" : "no alpha");
156 switch (filter_level)
158 case ART_FILTER_NEAREST:
159 printf ("ART_FILTER_NEAREST\n");
161 case ART_FILTER_TILES:
162 printf ("ART_FILTER_TILES\n");
164 case ART_FILTER_BILINEAR:
165 printf ("ART_FILTER_BILINEAR\n");
167 case ART_FILTER_HYPER:
168 printf ("ART_FILTER_HYPER\n");
172 printf("\t\t\titers\ttotal\t\tmsecs/iter\tMpixels/sec\t\n");
175 if (!(src_has_alpha && !dest_has_alpha))
178 for (i = 0; i < ITERS; i++)
180 pixops_scale (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
181 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
182 (double)dest_width / src_width, (double)dest_height / src_height,
185 scale_times[src_index][dest_index][filter_level] =
186 stop_timing (" scale\t\t", ITERS, dest_height * dest_width);
190 for (i = 0; i < ITERS; i++)
192 pixops_composite (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
193 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
194 (double)dest_width / src_width, (double)dest_height / src_height,
197 composite_times[src_index][dest_index][filter_level] =
198 stop_timing (" composite\t\t", ITERS, dest_height * dest_width);
201 for (i = 0; i < ITERS; i++)
203 pixops_composite_color (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
204 src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
205 (double)dest_width / src_width, (double)dest_height / src_height,
206 filter_level, 255, 0, 0, 16, 0xaaaaaa, 0x555555);
208 composite_color_times[src_index][dest_index][filter_level] =
209 stop_timing (" composite color\t", ITERS, dest_height * dest_width);
219 printf ("SCALE\n=====\n\n");
220 dump_array (scale_times);
222 printf ("COMPOSITE\n=========\n\n");
223 dump_array (composite_times);
225 printf ("COMPOSITE_COLOR\n===============\n\n");
226 dump_array (composite_color_times);