summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiarhei Siamashka <siarhei.siamashka@gmail.com>2011-05-16 00:05:50 +0300
committerSiarhei Siamashka <siarhei.siamashka@gmail.com>2011-05-16 00:20:43 +0300
commitc3fcbee5a793770b616d6e24b5dfdfcd97a7539b (patch)
tree875468b3e972e5f384f66aca22fcb61cf8485774
parenta72b75c23bf56053b901380a6a067cf1324d0011 (diff)
A new random scaling benchmark and reporting MPix/s statsHEADmaster
The new benchmark tests scaling with random scale factors uniformly distributed between 0.5 and 1.427050983 (so that on average the number of pixels in the source and destination images is roughly equally balanced). Also now we are reporting MPix/s numbers which can be directly compared to memory bandwidth on the target systems.
-rw-r--r--main.c167
1 files changed, 108 insertions, 59 deletions
diff --git a/main.c b/main.c
index 1dc0660..b35612e 100644
--- a/main.c
+++ b/main.c
@@ -30,6 +30,7 @@ int win_w = 320;
int win_h = 320;
static Display *disp = NULL;
static Window win;
+long long pixels_counter;
double
get_time(void)
@@ -46,6 +47,7 @@ time_test(char *description, void (*func) (void))
double t1, t2, t;
int i;
+ pixels_counter = 0;
printf("---------------------------------------------------------------\n");
printf("Test: %s\n", description);
t1 = get_time();
@@ -54,6 +56,8 @@ time_test(char *description, void (*func) (void))
t2 = get_time();
t = t2 - t1;
printf("Time: %3.3f sec.\n", t);
+ if (pixels_counter > 0 && t > 0)
+ printf("Perf: %3.3f MPix/s\n", (double)pixels_counter / ((double)t * 1000000.));
}
Xrender_Surf *
@@ -216,6 +220,7 @@ test_over_x(void)
x = rand() % (surf_win->w - surf_img->w);
y = rand() % (surf_win->h - surf_img->h);
xrender_surf_blend(disp, surf_img, surf_win, x, y, surf_img->w, surf_img->h, 1);
+ pixels_counter += surf_img->w * surf_img->h;
}
void
@@ -226,6 +231,7 @@ test_over_off_x(void)
x = rand() % (surf_off->w - surf_img->w);
y = rand() % (surf_off->h - surf_img->h);
xrender_surf_blend(disp, surf_img, surf_off, x, y, surf_img->w, surf_img->h, 1);
+ pixels_counter += surf_img->w * surf_img->h;
}
void
@@ -245,6 +251,7 @@ test_over_imlib2(void)
y = rand() % (hh - h);
imlib_context_set_image(im_win);
imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, x, y, w, h);
+ pixels_counter += w * h;
}
void
@@ -255,6 +262,7 @@ test_over_scale_half_x(void)
x = rand() % (surf_win->w - (surf_img->w / 2));
y = rand() % (surf_win->h - (surf_img->h / 2));
xrender_surf_blend(disp, surf_img, surf_win, x, y, surf_img->w / 2, surf_img->h / 2, 0);
+ pixels_counter += (surf_img->w / 2) * (surf_img->h / 2);
}
void
@@ -265,6 +273,7 @@ test_over_off_scale_half_x(void)
x = rand() % (surf_off->w - (surf_img->w / 2));
y = rand() % (surf_off->h - (surf_img->h / 2));
xrender_surf_blend(disp, surf_img, surf_off, x, y, surf_img->w / 2, surf_img->h / 2, 0);
+ pixels_counter += (surf_img->w / 2) * (surf_img->h / 2);
}
void
@@ -284,6 +293,7 @@ test_over_scale_half_imlib2(void)
y = rand() % (hh - (h / 2));
imlib_context_set_image(im_win);
imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, x, y, w / 2, h / 2);
+ pixels_counter += (w / 2) * (h / 2);
}
void
@@ -294,6 +304,7 @@ test_over_scale_double_smooth_x(void)
x = rand() % (surf_win->w - (surf_img->w * 2));
y = rand() % (surf_win->h - (surf_img->h * 2));
xrender_surf_blend(disp, surf_img, surf_win, x, y, surf_img->w * 2, surf_img->h * 2, 1);
+ pixels_counter += (surf_img->w * 2) * (surf_img->h * 2);
}
void
@@ -304,6 +315,7 @@ test_over_off_scale_double_smooth_x(void)
x = rand() % (surf_off->w - (surf_img->w * 2));
y = rand() % (surf_off->h - (surf_img->h * 2));
xrender_surf_blend(disp, surf_img, surf_off, x, y, surf_img->w * 2, surf_img->h * 2, 1);
+ pixels_counter += (surf_img->w * 2) * (surf_img->h * 2);
}
void
@@ -323,6 +335,7 @@ test_over_scale_double_smooth_imlib2(void)
y = rand() % (hh - (h * 2));
imlib_context_set_image(im_win);
imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, x, y, w * 2, h * 2);
+ pixels_counter += (w * 2) * (h * 2);
}
void
@@ -333,6 +346,7 @@ test_over_scale_double_nearest_x(void)
x = rand() % (surf_win->w - (surf_img->w * 2));
y = rand() % (surf_win->h - (surf_img->h * 2));
xrender_surf_blend(disp, surf_img, surf_win, x, y, surf_img->w * 2, surf_img->h * 2, 0);
+ pixels_counter += (surf_img->w * 2) * (surf_img->h * 2);
}
void
@@ -343,6 +357,7 @@ test_over_off_scale_double_nearest_x(void)
x = rand() % (surf_off->w - (surf_img->w * 2));
y = rand() % (surf_off->h - (surf_img->h * 2));
xrender_surf_blend(disp, surf_img, surf_off, x, y, surf_img->w * 2, surf_img->h * 2, 0);
+ pixels_counter += (surf_img->w * 2) * (surf_img->h * 2);
}
void
@@ -362,93 +377,126 @@ test_over_scale_double_nearest_imlib2(void)
y = rand() % (hh - (h * 2));
imlib_context_set_image(im_win);
imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, x, y, w * 2, h * 2);
+ pixels_counter += (w * 2) * (h * 2);
}
-int count = 0;
+/*
+ * A coefficient responsible for making the number of
+ * read and written pixels approximately the same
+ */
+#define MAX_SCALE 1.427050983
void
-test_over_scale_general_nearest_x(void)
+test_over_scale_rand_smooth_x(void)
{
- int w, h;
-
- w = 1 + ((surf_img->w * count) / (REPS / 16));
- h = 1 + ((surf_img->h * count) / (REPS / 16));
- xrender_surf_blend(disp, surf_img, surf_win, 0, 0, w, h, 0);
- count++;
+ int x, y;
+ int max_w = MAX_SCALE * surf_img->w;
+ int max_h = MAX_SCALE * surf_img->h;
+ int dst_w = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+ int dst_h = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+
+ x = rand() % (surf_win->w - dst_w);
+ y = rand() % (surf_win->h - dst_h);
+ xrender_surf_blend(disp, surf_img, surf_win, x, y, dst_w, dst_h, 1);
+ pixels_counter += dst_w * dst_h;
}
void
-test_over_off_scale_general_nearest_x(void)
+test_over_off_scale_rand_smooth_x(void)
{
- int w, h;
-
- w = 1 + ((surf_img->w * count) / (REPS / 16));
- h = 1 + ((surf_img->h * count) / (REPS / 16));
- xrender_surf_blend(disp, surf_img, surf_off, 0, 0, w, h, 0);
- count++;
+ int x, y;
+ int max_w, max_h, dst_w, dst_h;
+ max_w = MAX_SCALE * surf_img->w;
+ max_h = MAX_SCALE * surf_img->h;
+ dst_w = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+ dst_h = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+
+ x = rand() % (surf_off->w - dst_w);
+ y = rand() % (surf_off->h - dst_h);
+ xrender_surf_blend(disp, surf_img, surf_off, x, y, dst_w, dst_h, 1);
+ pixels_counter += dst_w * dst_h;
}
void
-test_over_scale_general_nearest_imlib2(void)
+test_over_scale_rand_smooth_imlib2(void)
{
+ int x, y;
int w, h, ww, hh;
-
- imlib_context_set_anti_alias(0);
+ int max_w, max_h, dst_w, dst_h;
+
+ imlib_context_set_anti_alias(1);
imlib_context_set_image(im_win);
ww = imlib_image_get_width();
hh = imlib_image_get_height();
imlib_context_set_image(im_img);
w = imlib_image_get_width();
h = imlib_image_get_height();
- ww = 1 + ((w * count) / (REPS / 16));
- hh = 1 + ((h * count) / (REPS / 16));
- imlib_context_set_image(im_win);
- imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, 0, 0, ww, hh);
- count++;
+ max_w = MAX_SCALE * w;
+ max_h = MAX_SCALE * h;
+ dst_w = w / 2 + rand() % (max_w - w / 2);
+ dst_h = w / 2 + rand() % (max_w - w / 2);
+ x = rand() % (ww - dst_w);
+ y = rand() % (hh - dst_h);
+ imlib_context_set_image(im_win);
+ imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, x, y, dst_w, dst_h);
+ pixels_counter += dst_w * dst_h;
}
void
-test_over_scale_general_smooth_x(void)
+test_over_scale_rand_nearest_x(void)
{
- int w, h;
-
- w = 1 + ((surf_img->w * count) / (REPS / 16));
- h = 1 + ((surf_img->h * count) / (REPS / 16));
- xrender_surf_blend(disp, surf_img, surf_win, 0, 0, w, h, 1);
- count++;
+ int x, y;
+ int max_w, max_h, dst_w, dst_h;
+ max_w = MAX_SCALE * surf_img->w;
+ max_h = MAX_SCALE * surf_img->h;
+ dst_w = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+ dst_h = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+
+ x = rand() % (surf_off->w - dst_w);
+ y = rand() % (surf_off->h - dst_h);
+ xrender_surf_blend(disp, surf_img, surf_win, x, y, dst_w, dst_h, 0);
+ pixels_counter += dst_w * dst_h;
}
void
-test_over_off_scale_general_smooth_x(void)
+test_over_off_scale_rand_nearest_x(void)
{
- int w, h;
-
- w = 1 + ((surf_img->w * count) / (REPS / 16));
- h = 1 + ((surf_img->h * count) / (REPS / 16));
- xrender_surf_blend(disp, surf_img, surf_off, 0, 0, w, h, 1);
- count++;
+ int x, y;
+ int max_w, max_h, dst_w, dst_h;
+ max_w = MAX_SCALE * surf_img->w;
+ max_h = MAX_SCALE * surf_img->h;
+ dst_w = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+ dst_h = surf_img->w / 2 + rand() % (max_w - surf_img->w / 2);
+
+ x = rand() % (surf_off->w - dst_w);
+ y = rand() % (surf_off->h - dst_h);
+ xrender_surf_blend(disp, surf_img, surf_off, x, y, dst_w, dst_h, 0);
+ pixels_counter += dst_w * dst_h;
}
void
-test_over_scale_general_smooth_imlib2(void)
+test_over_scale_rand_nearest_imlib2(void)
{
+ int x, y;
int w, h, ww, hh;
+ int max_w, max_h, dst_w, dst_h;
+ imlib_context_set_anti_alias(0);
imlib_context_set_image(im_win);
ww = imlib_image_get_width();
hh = imlib_image_get_height();
imlib_context_set_image(im_img);
w = imlib_image_get_width();
h = imlib_image_get_height();
- ww = 1 + ((w * count) / (REPS / 16));
- hh = 1 + ((h * count) / (REPS / 16));
- if ((ww < w) && (hh < h))
- imlib_context_set_anti_alias(0);
- else
- imlib_context_set_anti_alias(1);
- imlib_context_set_image(im_win);
- imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, 0, 0, ww, hh);
- count++;
+ max_w = MAX_SCALE * w;
+ max_h = MAX_SCALE * h;
+ dst_w = w / 2 + rand() % (max_w - w / 2);
+ dst_h = w / 2 + rand() % (max_w - w / 2);
+ x = rand() % (ww - dst_w);
+ y = rand() % (hh - dst_h);
+ imlib_context_set_image(im_win);
+ imlib_blend_image_onto_image(im_img, 0, 0, 0, w, h, x, y, dst_w, dst_h);
+ pixels_counter += dst_w * dst_h;
}
void
@@ -530,13 +578,14 @@ main_loop(void)
imlib_context_set_colormap(DefaultColormap(disp, DefaultScreen(disp)));
imlib_context_set_drawable(win);
imlib_render_image_on_drawable(0, 0);
+ sleep(2);
printf("*** ROUND 6 ***\n");
- count = 0;
- time_test("Test Xrender doing general nearest scaled Over blends", test_over_scale_general_nearest_x);
- count = 0;
- time_test("Test Xrender (offscreen) doing general nearest scaled Over blends", test_over_off_scale_general_nearest_x);
- count = 0;
- time_test("Test Imlib2 doing general nearest scaled Over blends", test_over_scale_general_nearest_imlib2);
+ srand(7);
+ time_test("Test Xrender doing random nearest scaled Over blends", test_over_scale_rand_nearest_x);
+ srand(7);
+ time_test("Test Xrender (offscreen) doing random nearest scaled Over blends", test_over_off_scale_rand_nearest_x);
+ srand(7);
+ time_test("Test Imlib2 doing random nearest scaled Over blends", test_over_scale_rand_nearest_imlib2);
imlib_context_set_image(im_win);
imlib_context_set_display(disp);
imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));
@@ -545,12 +594,12 @@ main_loop(void)
imlib_render_image_on_drawable(0, 0);
sleep(2);
printf("*** ROUND 7 ***\n");
- count = 0;
- time_test("Test Xrender doing general smooth scaled Over blends", test_over_scale_general_smooth_x);
- count = 0;
- time_test("Test Xrender (offscreen) doing general smooth scaled Over blends", test_over_off_scale_general_smooth_x);
- count = 0;
- time_test("Test Imlib2 doing general smooth scaled Over blends", test_over_scale_general_smooth_imlib2);
+ srand(7);
+ time_test("Test Xrender doing random smooth scaled Over blends", test_over_scale_rand_smooth_x);
+ srand(7);
+ time_test("Test Xrender (offscreen) doing random smooth scaled Over blends", test_over_off_scale_rand_smooth_x);
+ srand(7);
+ time_test("Test Imlib2 doing random smooth scaled Over blends", test_over_scale_rand_smooth_imlib2);
imlib_context_set_image(im_win);
imlib_context_set_display(disp);
imlib_context_set_visual(DefaultVisual(disp, DefaultScreen(disp)));