New benchmarks: copy and composite
authorMikko Rasa <mikko.rasa@movial.fi>
Wed, 25 Mar 2009 12:59:27 +0000 (14:59 +0200)
committerMikko Rasa <mikko.rasa@movial.fi>
Wed, 25 Mar 2009 12:59:27 +0000 (14:59 +0200)
Use XRenderCreateSolidFill instead of hand-crafting a 1x1 picture
Improved guesstimate of the trial batch size in statistical mode

main.c
synthetic.bench

diff --git a/main.c b/main.c
index e5e58d8..c2dc6a6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -44,13 +44,17 @@ void sync();
 void nop();
 void create_destroy_pixmap();
 void create_destroy_picture();
+void random_color(XRenderColor *color, int alpha);
 void fill_rectangle();
 void composite_trapezoid();
 void draw_string8();
+void copy_area();
+void composite_copy_area();
 
 Display *dpy;
 Window wnd;
 Pixmap pxm;
+GC gc;
 int depth;
 XRenderPictFormat *pfmt;
 Picture pict;
@@ -62,6 +66,7 @@ XftFont *font;
 XftDraw *ftdraw;
 char *text;
 unsigned textlen;
+int copymode;
 
 int main(int argc, char **argv)
 {
@@ -69,10 +74,7 @@ int main(int argc, char **argv)
        Visual *visual;
        Colormap cmap;
        Window root;
-       Pixmap srcpxm;
        XRenderPictFormat pft;
-       XRenderPictFormat *pfmt32;
-       XRenderPictureAttributes pattr;
        char *test_name=NULL;
        unsigned batch=3000;
        unsigned time=1000;
@@ -80,7 +82,6 @@ int main(int argc, char **argv)
        FILE *in=NULL, *out;
        float total=0;
        float weight=1.0;
-       XRenderColor color;
        int prec;
 
        if(argc>=2)
@@ -131,16 +132,6 @@ int main(int argc, char **argv)
        pfmt=XRenderFindFormat(dpy, PictFormatDepth, &pft, 1);
        pict=XRenderCreatePicture(dpy, wnd, pfmt, 0, NULL);
 
-       pfmt32=XRenderFindStandardFormat(dpy, PictStandardARGB32);
-       srcpxm=XCreatePixmap(dpy, wnd, 1, 1, 32);
-       pattr.repeat=RepeatNormal;
-       srcpict=XRenderCreatePicture(dpy, srcpxm, pfmt32, CPRepeat, &pattr);
-       
-       color.red=0xFFFF;
-       color.green=0xFFFF;
-       color.blue=0xFFFF;
-       XRenderFillRectangle(dpy, PictOpSrc, srcpict, &color, 0, 0, 1, 1);
-
        op=PictOpSrc;
        while(1)
        {
@@ -198,9 +189,24 @@ int main(int argc, char **argv)
                                        op=PictOpSrc;
                                else if(!strcmp(delim+1, "add"))
                                        op=PictOpAdd;
+                               else
+                                       fprintf(stderr, "Unknown operator '%s'\n", delim+1);
                        }
                        else if(!strncmp(line, "weight", delim-line))
                                weight=strtod(delim+1, NULL);
+                       else if(!strncmp(line, "copymode", delim-line))
+                       {
+                               if(!strcmp(delim+1, "pxm>wnd"))
+                                       copymode=0;
+                               else if(!strcmp(delim+1, "pxm>pxm"))
+                                       copymode=1;
+                               else if(!strcmp(delim+1, "wnd>wnd"))
+                                       copymode=2;
+                               else if(!strcmp(delim+1, "wnd>pxm"))
+                                       copymode=3;
+                               else
+                                       fprintf(stderr, "Unknown copy mode '%s'\n", delim+1);
+                       }
                        else
                                fprintf(stderr, "Unknown assignment '%s'\n", line);
                        continue;
@@ -222,9 +228,9 @@ int main(int argc, char **argv)
                {
                        if(!strncmp(line, "run", delim-line))
                        {
-                               printf("%s:\n", test_name);
                                Result res;
                                unsigned size=0;
+                               printf("%s:\n", test_name);
                                if(!strcmp(delim+1, "rect") || !strcmp(delim+1, "rectangle"))
                                {
                                        size=width*height;
@@ -232,8 +238,12 @@ int main(int argc, char **argv)
                                }
                                else if(!strcmp(delim+1, "trapezoid"))
                                {
+                                       XRenderColor color;
+                                       random_color(&color, 0);
                                        size=width*height;
+                                       srcpict=XRenderCreateSolidFill(dpy, &color);
                                        res=measure(composite_trapezoid, batch, time, type);
+                                       XRenderFreePicture(dpy, srcpict);
                                }
                                else if(!strcmp(delim+1, "text"))
                                {
@@ -242,6 +252,27 @@ int main(int argc, char **argv)
                                        res=measure(draw_string8, batch, time, type);
                                        XftDrawDestroy(ftdraw);
                                }
+                               else if(!strcmp(delim+1, "copy"))
+                               {
+                                       size=width*height;
+                                       pxm=XCreatePixmap(dpy, wnd, 640, 480, depth);
+                                       gc=XCreateGC(dpy, wnd, 0, NULL);
+                                       XCopyArea(dpy, wnd, pxm, gc, 0, 0, 640, 480, 0, 0);
+                                       res=measure(copy_area, batch, time, type);
+                                       XFreeGC(dpy, gc);
+                                       XFreePixmap(dpy, pxm);
+                               }
+                               else if(!strcmp(delim+1, "composite"))
+                               {
+                                       size=width*height;
+                                       pxm=XCreatePixmap(dpy, wnd, 640, 480, depth);
+                                       gc=XCreateGC(dpy, wnd, 0, NULL);
+                                       XCopyArea(dpy, wnd, pxm, gc, 0, 0, 640, 480, 0, 0);
+                                       XFreeGC(dpy, gc);
+                                       srcpict=XRenderCreatePicture(dpy, pxm, pfmt, 0, NULL);
+                                       res=measure(composite_copy_area, batch, time, type);
+                                       XFreePixmap(dpy, pxm);
+                               }
                                else if(!strcmp(delim+1, "pixmap"))
                                        res=measure(create_destroy_pixmap, batch, time, type);
                                else if(!strcmp(delim+1, "picture"))
@@ -320,7 +351,8 @@ Result measure(void (*func)(), unsigned batch, unsigned time, MeasureType type)
                float stddev=0;
 
                nbatches=batch;
-               speed=measure(func, 100, 100, NORMAL).ops_per_sec;
+               i=time/nbatches;
+               speed=measure(func, 100, (i<1000 ? i<100 ? 100 : i : 1000), NORMAL).ops_per_sec;
                batch=(long long)speed*time/1000/nbatches;
 
                data=(unsigned *)malloc(nbatches*sizeof(unsigned));
@@ -477,3 +509,41 @@ void draw_string8()
        y=rand()%(481-extents.height);
        XftDrawString8(ftdraw, &ftcolor, font, x, y, textptr, textlen);
 }
+
+void copy_area()
+{
+       int x1, y1;
+       int x2, y2;
+
+       x1=rand()%(641-width);
+       y1=rand()%(481-height);
+       x2=rand()%(641-width);
+       y2=rand()%(481-height);
+
+       switch(copymode)
+       {
+       case 0: XCopyArea(dpy, pxm, wnd, gc, x1, y1, width, height, x2, y2); break;
+       case 1: XCopyArea(dpy, pxm, pxm, gc, x1, y1, width, height, x2, y2); break;
+       case 2: XCopyArea(dpy, wnd, wnd, gc, x1, y1, width, height, x2, y2); break;
+       case 3: XCopyArea(dpy, wnd, pxm, gc, x1, y1, width, height, x2, y2); break;
+       }
+}
+
+void composite_copy_area()
+{
+       int x1, y1;
+       int x2, y2;
+
+       x1=rand()%(641-width);
+       y1=rand()%(481-height);
+       x2=rand()%(641-width);
+       y2=rand()%(481-height);
+
+       switch(copymode)
+       {
+       case 0: XRenderComposite(dpy, op, srcpict, None, pict, x1, y1, 0, 0, x2, y2, width, height); break;
+       case 1: XRenderComposite(dpy, op, srcpict, None, srcpict, x1, y1, 0, 0, x2, y2, width, height); break;
+       case 2: XRenderComposite(dpy, op, pict, None, pict, x1, y1, 0, 0, x2, y2, width, height); break;
+       case 3: XRenderComposite(dpy, op, pict, None, srcpict, x1, y1, 0, 0, x2, y2, width, height); break;
+       }
+}
index 9456413..e82020e 100644 (file)
@@ -86,6 +86,34 @@ Rect 8x128 Over:
        size=8x128
        run rect
 
+copymode=pxm>wnd
+
+Copy 32x32:
+       size=32x32
+       run copy
+
+Copy 128x128:
+       size=128x128
+       run copy
+
+Composite 32x32:
+       size=32x32
+       run composite
+
+Composite 128x128:
+       size=128x128
+       run composite
+
+copymode=pxm>pxm
+
+Copy 128x128 pixmap:
+       size=128x128
+       run copy
+
+Composite 128x128 pixmap:
+       size=128x128
+       run composite
+
 randomtext=20
 
 Text 8px: