xcb-studies/studies/xlib_demo.cc

44 lines
1003 B
C++

#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
double get_time(void) {
struct timeval timev;
gettimeofday(&timev, NULL);
return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
}
int main() {
int count = 500;
Atom* atoms_x = (Atom*)malloc(count * sizeof(atoms_x));
char** names;
double end, diff_x;
/* init names */
names = (char**)malloc(count * sizeof(char*));
for (int i = 0; i < count; ++i) {
char buf[100];
sprintf(buf, "NAME%d", i);
names[i] = strdup(buf);
}
auto start = get_time();
auto disp = XOpenDisplay(getenv("DISPLAY"));
for (int i = 0; i < count; ++i)
atoms_x[i] = XInternAtom(disp, names[i], 0);
end = get_time();
XCloseDisplay(disp);
diff_x = end - start;
printf("Xlib use time : %f\n", diff_x);
free(atoms_x);
for (int i = 0; i < count; ++i)
free(names[i]);
free(names);
return 0;
}