SERIAL: core: use local variable uport in uart_set_termios()
[linux-2.6.git] / lib / interval_tree_test_main.c
blobb25903987f7aeb046dc48b75fd3bafe4d4967533
1 #include <linux/module.h>
2 #include <linux/interval_tree.h>
3 #include <linux/random.h>
4 #include <asm/timex.h>
6 #define NODES 100
7 #define PERF_LOOPS 100000
8 #define SEARCHES 100
9 #define SEARCH_LOOPS 10000
11 static struct rb_root root = RB_ROOT;
12 static struct interval_tree_node nodes[NODES];
13 static u32 queries[SEARCHES];
15 static struct rnd_state rnd;
17 static inline unsigned long
18 search(unsigned long query, struct rb_root *root)
20 struct interval_tree_node *node;
21 unsigned long results = 0;
23 for (node = interval_tree_iter_first(root, query, query); node;
24 node = interval_tree_iter_next(node, query, query))
25 results++;
26 return results;
29 static void init(void)
31 int i;
32 for (i = 0; i < NODES; i++) {
33 u32 a = prandom32(&rnd), b = prandom32(&rnd);
34 if (a <= b) {
35 nodes[i].start = a;
36 nodes[i].last = b;
37 } else {
38 nodes[i].start = b;
39 nodes[i].last = a;
42 for (i = 0; i < SEARCHES; i++)
43 queries[i] = prandom32(&rnd);
46 static int interval_tree_test_init(void)
48 int i, j;
49 unsigned long results;
50 cycles_t time1, time2, time;
52 printk(KERN_ALERT "interval tree insert/remove");
54 prandom32_seed(&rnd, 3141592653589793238ULL);
55 init();
57 time1 = get_cycles();
59 for (i = 0; i < PERF_LOOPS; i++) {
60 for (j = 0; j < NODES; j++)
61 interval_tree_insert(nodes + j, &root);
62 for (j = 0; j < NODES; j++)
63 interval_tree_remove(nodes + j, &root);
66 time2 = get_cycles();
67 time = time2 - time1;
69 time = div_u64(time, PERF_LOOPS);
70 printk(" -> %llu cycles\n", (unsigned long long)time);
72 printk(KERN_ALERT "interval tree search");
74 for (j = 0; j < NODES; j++)
75 interval_tree_insert(nodes + j, &root);
77 time1 = get_cycles();
79 results = 0;
80 for (i = 0; i < SEARCH_LOOPS; i++)
81 for (j = 0; j < SEARCHES; j++)
82 results += search(queries[j], &root);
84 time2 = get_cycles();
85 time = time2 - time1;
87 time = div_u64(time, SEARCH_LOOPS);
88 results = div_u64(results, SEARCH_LOOPS);
89 printk(" -> %llu cycles (%lu results)\n",
90 (unsigned long long)time, results);
92 return -EAGAIN; /* Fail will directly unload the module */
95 static void interval_tree_test_exit(void)
97 printk(KERN_ALERT "test exit\n");
100 module_init(interval_tree_test_init)
101 module_exit(interval_tree_test_exit)
103 MODULE_LICENSE("GPL");
104 MODULE_AUTHOR("Michel Lespinasse");
105 MODULE_DESCRIPTION("Interval Tree test");