Convert all uint32/16/8 to _t in source3/locking.
[Samba.git] / ctdb / tests / src / rb_perftest.c
blob1760cd1149f850dbdde2b02f54cbc709a95fabbc
1 /*
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/>.
20 #include "includes.h"
21 #include "lib/events/events.h"
22 #include "lib/util/dlinklist.h"
23 #include "system/filesys.h"
24 #include "popt.h"
25 #include "cmdline.h"
27 #include <sys/time.h>
28 #include <time.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;
49 struct list_node {
50 struct list_node *prev, *next;
54 main program
56 int main(int argc, const char *argv[])
58 struct poptOption popt_options[] = {
59 POPT_AUTOHELP
60 POPT_CTDB_CMDLINE
61 { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
62 POPT_TABLEEND
64 int opt;
65 const char **extra_argv;
66 int extra_argc = 0;
67 int ret;
68 poptContext pc;
69 struct event_context *ev;
70 double elapsed;
71 int i;
72 trbt_tree_t *tree;
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) {
78 switch (opt) {
79 default:
80 fprintf(stderr, "Invalid option %s: %s\n",
81 poptBadOption(pc, 0), poptStrerror(opt));
82 exit(1);
86 /* setup the remaining options for the main program to use */
87 extra_argv = poptGetArgs(pc);
88 if (extra_argv) {
89 extra_argv++;
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);
98 start_timer();
99 for (i=0;i<num_records;i++) {
100 trbt_insert32(tree, i, NULL);
102 elapsed=end_timer();
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);
109 start_timer();
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);
119 elapsed=end_timer();
120 printf("%f seconds\n",(float)elapsed);
122 return 0;