[Xcb-commit] tutorial.mdwn
XCB site
xcb at freedesktop.org
Mon Sep 14 18:33:18 PDT 2009
tutorial.mdwn | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
New commits:
commit 7dafb59aa9a2e816f7df05c5a8b0dd97ce6f2b9d
Author: dfries <dfries at web>
Date: Mon Sep 14 18:33:18 2009 -0700
add XInternAtoms array version and contrast with XCB
diff --git a/tutorial.mdwn b/tutorial.mdwn
index 0a598c6..918e608 100644
--- a/tutorial.mdwn
+++ b/tutorial.mdwn
@@ -86,6 +86,8 @@ The total time is `N * T_write + max (0, T_round_trip - (N-1) * T_write) + N * T
Here is a program that computes the time to create 500 atoms with Xlib and XCB. It shows the Xlib way, the bad XCB way (which is similar to Xlib) and the good XCB way. On my computer, XCB is 25 times faster than Xlib. On another random machine XCB has been observed to be up to 117 times faster than Xlib, on rare occasions.
+To further compare Xlib to XCB, there's a XInternAtoms routine. It's the Xlib method to request all the atoms in an array at one time to help hide the latency. Mostly the good Xlib time takes twice the time as the good XCB time. It also highlights the complexity of using XCB, 3 simple statements for Xlib vs 9 statements including two loops for XCB. If this simple test was expanded beyond requesting Atoms, XCB would allow submitting all the various requests at one time, Xlib wouldn't.
+
/* It's a good idea to paste this and other long code examples
into a text editor for easier reading */
@@ -139,7 +141,19 @@ Here is a program that computes the time to create 500 atoms with Xlib and XCB.
atoms[i] = XInternAtom(display, names[i], 0);
}
}
+
+ /*
+ Request all atoms at once.
+ */
+ void
+ useXlibProperly (char **names,
+ Display *display ) {
+ Atom atoms[NUM_NAMES];
+ if(!XInternAtoms(display, names, NUM_NAMES, 0, atoms))
+ fprintf(stderr, "XInternAtoms failed\n");
+ }
+
/*
*/
@@ -207,13 +221,16 @@ Here is a program that computes the time to create 500 atoms with Xlib and XCB.
}
/* do tests */
- double start, XlibTime, XCBBadTime, XCBGoodTime;
+ double start, XlibTime, XlibGoodTime, XCBBadTime, XCBGoodTime;
/* test Xlib */
Display *display = XOpenDisplay (NULL);
start = get_time ();
useXlib (names, display);
XlibTime = get_time () - start;
+ start = get_time ();
+ useXlibProperly (names, display);
+ XlibGoodTime = get_time () - start;
XCloseDisplay (display);
/* test XCB */
@@ -227,11 +244,13 @@ Here is a program that computes the time to create 500 atoms with Xlib and XCB.
xcb_disconnect (connection);
/* report times */
- printf ("Xlib time : %f\n", XlibTime);
+ printf ("Bad Xlib time : %f\n", XlibTime);
+ printf ("Good Xlib time : %f\n", XlibGoodTime);
printf ("Bad xcb time : %f\n", XCBBadTime);
printf ("Good xcb time : %f\n", XCBGoodTime);
printf ("ratio of good xcb time to bad xcb time: %f\n", XCBGoodTime / XCBBadTime);
printf ("ratio of Xlib time to good xcb time: %f\n", XlibTime / XCBGoodTime);
+ printf ("ratio of good Xlib time to bad Xlib time: %f\n", XlibGoodTime / XlibTime);
return 0;
}
More information about the xcb-commit
mailing list