summaryrefslogtreecommitdiff
path: root/innobase/ha/ts/tsha.c
blob: fd9a2e12f6ec7bee11545348c3c4fa9d80d85ec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/************************************************************************
The test module for hash table

(c) 1994, 1995 Innobase Oy

Created 1/25/1994 Heikki Tuuri
*************************************************************************/

#include "ut0ut.h"
#include "ha0ha.h"
#include "mem0mem.h"
#include "sync0sync.h"

ulint	ulint_array[200000];

void 
test1(void)
{
	hash_table_t*	table1;
	ulint		i;
	ulint		n313			= 313;
	ulint		n414			= 414;
	
	printf("------------------------------------------------\n");
	printf("TEST 1. BASIC TEST\n");

	table1 = ha_create(50000);
	
	ha_insert_for_fold(table1, 313, &n313);
	
	ha_insert_for_fold(table1, 313, &n414);

	ut_a(ha_validate(table1));

	ha_delete(table1, 313, &n313);
	ha_delete(table1, 313, &n414);

	ut_a(ha_validate(table1));

	printf("------------------------------------------------\n");
	printf("TEST 2. TEST OF MASSIVE INSERTS AND DELETES\n");

	table1 = ha_create(10000);

	for (i = 0; i < 200000; i++) {
		ulint_array[i] = i;
	}

	for (i = 0; i < 50000; i++) {
		ha_insert_for_fold(table1, i * 7, ulint_array + i);
	}
	
	ut_a(ha_validate(table1));

	for (i = 0; i < 50000; i++) {
		ha_delete(table1, i * 7, ulint_array + i);
	}

	ut_a(ha_validate(table1));
}

void 
test2(void)
{
	hash_table_t*	table1;
	ulint		i;
	ulint		oldtm, tm;
	ha_node_t*	node;

	printf("------------------------------------------------\n");
	printf("TEST 3. SPEED TEST\n");

	table1 = ha_create(300000);
	
	oldtm = ut_clock();
	
	for (i = 0; i < 200000; i++) {
		ha_insert_for_fold(table1, i * 27877, ulint_array + i);
	}

	tm = ut_clock();

	printf("Wall clock time for %lu inserts %lu millisecs\n",
		i, tm - oldtm);
	
	oldtm = ut_clock();
	
	for (i = 0; i < 200000; i++) {
		node = ha_search(table1, i * 27877);
	}
	
	tm = ut_clock();

	printf("Wall clock time for %lu searches %lu millisecs\n",
		i, tm - oldtm);

	oldtm = ut_clock();

	for (i = 0; i < 200000; i++) {
		ha_delete(table1, i * 27877, ulint_array + i);
	}

	tm = ut_clock();

	printf("Wall clock time for %lu deletes %lu millisecs\n",
		i, tm - oldtm);
}

void 
main(void) 
{
	sync_init();
	mem_init(1000000);

	test1();

	test2();

	printf("TESTS COMPLETED SUCCESSFULLY!\n");
}