2 simple rb vs dlist benchmark
4 Copyright (C) Ronnie Sahlberg 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "lib/events/events.h"
22 #include "lib/util/dlinklist.h"
23 #include "system/filesys.h"
29 #include "common/rb_tree.h"
31 static struct timeval tp1,tp2;
33 static void start_timer(void)
35 gettimeofday(&tp1,NULL);
38 static double end_timer(void)
40 gettimeofday(&tp2,NULL);
41 return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
42 (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
46 static int num_records = 1000;
50 struct list_node *prev, *next;
56 int main(int argc, const char *argv[])
58 struct poptOption popt_options[] = {
61 { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
65 const char **extra_argv;
69 struct event_context *ev;
73 struct list_node *list, *list_new, *list_head=NULL;
75 pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
77 while ((opt = poptGetNextOpt(pc)) != -1) {
80 fprintf(stderr, "Invalid option %s: %s\n",
81 poptBadOption(pc, 0), poptStrerror(opt));
86 /* setup the remaining options for the main program to use */
87 extra_argv = poptGetArgs(pc);
90 while (extra_argv[extra_argc]) extra_argc++;
93 ev = event_context_init(NULL);
96 printf("testing tree insert for %d records\n", num_records);
97 tree = trbt_create(NULL);
99 for (i=0;i<num_records;i++) {
100 trbt_insert32(tree, i, NULL);
103 printf("%f seconds\n",(float)elapsed);
106 printf("testing dlist (worst case) add to tail for %d records\n", num_records);
107 list_new=talloc(NULL, struct list_node);
108 DLIST_ADD(list_head, list_new);
110 for (i=0;i<num_records;i++) {
111 for(list=list_head;list->next;list=list->next) {
112 /* the events code does a timeval_compare */
113 timeval_compare(&tp1, &tp2);
116 list_new=talloc(NULL, struct list_node);
117 DLIST_ADD_AFTER(list_head, list_new, list);
120 printf("%f seconds\n",(float)elapsed);