// gcc test.c -lX11 -o test #include #include #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000) static void wait_for_rendering(Display *dpy, Window win) { XImage *ximage = XGetImage(dpy, win, 0, 0, 1, 1, AllPlanes, ZPixmap); if (ximage != NULL) XDestroyImage(ximage); } int main() { Display *dpy; Window win; GC gc; XSetWindowAttributes attr; int width = 1000; int height = 800; int black, white, x, y, i, len; struct timeval t1, t2; char string[300]; char buf[256]; double time = -1; dpy = XOpenDisplay(NULL); black = BlackPixel(dpy, DefaultScreen(dpy)); white = WhitePixel(dpy, DefaultScreen(dpy)); attr.override_redirect = True; win = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, width, height, 0, DefaultDepth(dpy, DefaultScreen(dpy)), InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)), CWOverrideRedirect, &attr); XMapWindow(dpy, win); XSync(dpy, True); gc = XCreateGC(dpy, win, 0, NULL); for (i = 0; i < 95; i++) { string[i] = i + 32; string[i+95] = i + 32; string[i+95*2] = i + 32; } while (1) { gettimeofday(&t1, NULL); for (i = 0; i < 5; i++) { XSetForeground(dpy, gc, white); XFillRectangle(dpy, win, gc, 0, 0, width, height); XSetForeground(dpy, gc, black); XSetBackground(dpy, gc, white); len = sprintf(buf, "%.1f ms", time); XDrawImageString(dpy, win, gc, 5, 15, buf, len); for(y = 0; y < height/15; y ++) for(x = 0; x < width/30; x ++) XDrawImageString(dpy, win, gc, 5 + x*30 , 30 + y*15, "Test", 4); } wait_for_rendering(dpy, win); gettimeofday(&t2, NULL); /* decaying average over ~1s! */ if (time < 0) time = TIMEDIFF(t2, t1); else time = (49*time + TIMEDIFF(t2, t1))/50; // printf("%i ms\n", time); } return 0; }