13 #include <sys/socket.h>
16 static struct timeval tp1,tp2;
18 static void start_timer()
20 gettimeofday(&tp1,NULL);
23 static double end_timer()
25 gettimeofday(&tp2,NULL);
26 return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
27 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
32 /* hook into the front of the list */
33 #define DLIST_ADD(list, p) \
37 (p)->next = (p)->prev = NULL; \
46 /* remove an element from a list - element doesn't have to be in list. */
47 #define DLIST_REMOVE(list, p) \
49 if ((p) == (list)) { \
51 if (list) (list)->prev = NULL; \
53 if ((p)->prev) (p)->prev->next = (p)->next; \
54 if ((p)->next) (p)->next->prev = (p)->prev; \
56 if ((p) != (list)) (p)->next = (p)->prev = NULL; \
59 /* promote an element to the top of the list */
60 #define DLIST_PROMOTE(list, p) \
62 DLIST_REMOVE(list, p); \
68 struct foo *next, *prev;
72 static struct foo *list;
74 static struct foo *findit(const char *name)
77 for (f=list;f;f=f->next) {
78 if (strcmp(name, f->name) == 0) {
79 // if (f != list) DLIST_PROMOTE(list, f);
92 f = malloc(sizeof(*f));
93 asprintf(&f->name, "%u%s", i, "foobar");
101 asprintf(&name, "%u%s", i, "foobar");
103 for (j=0;j<100000;j++) {
106 printf("%s: %.2f usec/op\n", name, 1.0e6*end_timer()/j);