1 /* gcc `pkg-config --cflags --libs x11` -o rectangles rectangles.c */
9 #define ITERATIONS 4000
12 main (int argc, char **argv)
16 XSetWindowAttributes attr;
18 GC gc, gc_white, gc_black;
19 unsigned long gcmask = 0l;
21 struct timeval tv_start, tv_stop;
26 dpy = XOpenDisplay (NULL);
28 fprintf (stderr, "Failed to open display %s\n", XDisplayName (NULL));
32 attr.override_redirect = True;
33 win = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0,
34 600, 600, 0, DefaultDepth (dpy, DefaultScreen (dpy)),
35 InputOutput, DefaultVisual (dpy, DefaultScreen (dpy)),
36 CWOverrideRedirect, &attr);
39 gcvalues.function = GXcopy;
40 gcmask |= GCForeground;
41 gcvalues.foreground = WhitePixel (dpy, DefaultScreen (dpy));
42 gc_white = XCreateGC (dpy, win, gcmask, &gcvalues);
44 gcvalues.foreground = BlackPixel (dpy, DefaultScreen (dpy));
45 gc_black = XCreateGC (dpy, win, gcmask, &gcvalues);
47 XMapWindow (dpy, win);
50 for (i = 0; i < MEASUREMENTS; i++) {
51 /* Nothing fancy here, just a gettimeofday system call. */
52 gettimeofday (&tv_start, NULL);
53 for (j = 0; j < ITERATIONS; j++) {
54 XFillRectangle (dpy, win, gc, 0, 0, 500, 500);
60 /* Standard 1x1 XGetImage to wait for rendering to complete. */
61 ximage = XGetImage (dpy, win, 0, 0, 1, 1, AllPlanes, ZPixmap);
62 gettimeofday (&tv_stop, NULL);
63 XDestroyImage (ximage);
65 elapsed = tv_stop.tv_sec - tv_start.tv_sec +
66 (tv_stop.tv_usec - tv_start.tv_usec) / 1000000.0;
67 printf ("%d iterations @ %.4f msec ( %.1f/sec): 500x500 XFillRectangle\n",
68 ITERATIONS, elapsed * 1000 / ITERATIONS, ITERATIONS / elapsed);