benchmark for performance results
[cdsspec-compiler.git] / benchmark / cliffc-hashtable / main.cc.backup
1 #include <iostream>
2 #include <threads.h>
3 #include "cliffc_hashtable.h"
4
5 using namespace std;
6
7 template<typename TypeK, typename TypeV>
8 slot* const cliffc_hashtable<TypeK, TypeV>::MATCH_ANY = new slot(false, NULL);
9
10 template<typename TypeK, typename TypeV>
11 slot* const cliffc_hashtable<TypeK, TypeV>::NO_MATCH_OLD = new slot(false, NULL);
12
13 template<typename TypeK, typename TypeV>
14 slot* const cliffc_hashtable<TypeK, TypeV>::TOMBPRIME = new slot(true, NULL);
15
16 template<typename TypeK, typename TypeV>
17 slot* const cliffc_hashtable<TypeK, TypeV>::TOMBSTONE = new slot(false, NULL);
18
19
20 class IntWrapper {
21         private:
22                 public:
23             int _val;
24
25                 IntWrapper(int val) : _val(val) {}
26
27                 IntWrapper() : _val(0) {}
28
29                 IntWrapper(IntWrapper& copy) : _val(copy._val) {}
30
31                 int get() {
32                         return _val;
33                 }
34
35                 int hashCode() {
36                         return _val;
37                 }
38                 
39                 bool operator==(const IntWrapper& rhs) {
40                         return false;
41                 }
42
43                 bool equals(const void *another) {
44                         if (another == NULL)
45                                 return false;
46                         IntWrapper *ptr =
47                                 (IntWrapper*) another;
48                         return ptr->_val == _val;
49                 }
50 };
51
52 cliffc_hashtable<IntWrapper, IntWrapper> *table;
53 IntWrapper *val1, *val2;
54 IntWrapper *k0, *k1, *k2, *k3, *k4, *k5;
55 IntWrapper *v0, *v1, *v2, *v3, *v4, *v5;
56
57 void threadA(void *arg) {
58         //table->put(k1, v4);
59         table->put(k3, v3);
60         val1 = table->get(k2);
61         //table->put(k3, v3);
62         /*
63         val1 = table->get(k3);
64         if (val1 != NULL)
65                 model_print("val1: %d\n", val1->_val);
66         else
67                 model_print("val1: NULL\n");*/
68         //table->put(k3, v3);
69         
70 }
71
72 void threadB(void *arg) {
73         //table->put(k1, v1);
74         //table->put(k2, v4);
75         //table->put(k3, v3);
76 }
77
78 void threadMain(void *arg) {
79         table->put(k2, v2);
80         val1 = table->get(k3);
81         //val2 = table->get(k2);
82         /*
83         if (val1 != NULL)
84                 model_print("val1: %d\n", val1->_val);
85         else
86                 model_print("val1: NULL\n");
87         if (val2 != NULL)
88                 model_print("val2: %d\n", val2->_val);
89         else
90                 model_print("val2: NULL\n");*/
91 }
92
93 int user_main(int argc, char *argv[]) {
94         thrd_t t1, t2;
95         table = new cliffc_hashtable<IntWrapper, IntWrapper>(32);
96     k1 = new IntWrapper(3);
97         k2 = new IntWrapper(5);
98         k3 = new IntWrapper(11);
99         k4 = new IntWrapper(7);
100         k5 = new IntWrapper(13);
101
102         v1 = new IntWrapper(1024);
103         v2 = new IntWrapper(47);
104         v3 = new IntWrapper(73);
105         v4 = new IntWrapper(81);
106         v5 = new IntWrapper(99);
107
108         v0 = new IntWrapper(2048);
109         //table->put(k1, v0);
110         //table->put(k2, v0);
111         //model_print("hey\n");
112         thrd_create(&t1, threadA, NULL);
113         thrd_create(&t2, threadB, NULL);
114         threadMain(NULL);
115
116         thrd_join(t1);
117         thrd_join(t2);
118         /*
119         if (val1 == NULL) {
120                 cout << "val1: NULL" << endl;
121         } else {
122                 cout << val1->get() << endl;
123         }
124         //MODEL_ASSERT(val1 == NULL || val1->get() == 2 || val1->get() == 81);
125         if (val2 == NULL) {
126                 cout << "val2: NULL" << endl;
127         } else {
128                 cout << val2->get() << endl;
129         }
130         */
131         return 0;
132 }
133