~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/falcon/SyncTest.cpp

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        
44
44
        Sync sync(&starter, "SyncTest::test");
45
45
        Threads *threadBarn = new Threads(NULL, MAX_THREADS);
 
46
        int grandTotal = 0;
46
47
                
47
48
        for (int n = 1; n <= MAX_THREADS; ++n)
48
49
                {
49
50
                sync.lock(Exclusive);
 
51
                int collisions = syncObject.getCollisionCount();
50
52
                stop = false;
51
53
                int thd;
52
54
                
84
86
                for (thd = 0; thd < n; ++thd)
85
87
                        total += threads[thd].count;
86
88
                
87
 
                printf("%d threads, %d cycles:", n, total);
 
89
                if (n != 1)
 
90
                        grandTotal += total;
 
91
                        
 
92
                printf("%d threads, %s cycles, %s collisions\n", n, 
 
93
                                (const char*) format(total), 
 
94
                                (const char*) format(syncObject.getCollisionCount() - collisions));
88
95
 
 
96
                /***
89
97
                for (thd = 0; thd < n; ++thd)
90
98
                        printf(" %d", threads[thd].count);
91
99
                                        
92
100
                printf("\n");
 
101
                ***/
93
102
                }
94
103
        
 
104
        printf ("Average cycles %s\n", (const char*) format(grandTotal / (MAX_THREADS - 1)));
95
105
        threadBarn->shutdownAll();
96
106
        threadBarn->waitForAll();
97
107
        threadBarn->release();
117
127
                sync.unlock();
118
128
                }
119
129
}
 
130
 
 
131
JString SyncTest::format(long num)
 
132
{
 
133
        char temp[32];
 
134
        long number = num;
 
135
        char *p = temp + sizeof(temp);
 
136
        *--p = 0;
 
137
        
 
138
        if (number == 0)
 
139
                {
 
140
                *--p = '0';
 
141
                
 
142
                return p;
 
143
                }
 
144
        
 
145
        bool neg = false;
 
146
        
 
147
        if (number < 0)
 
148
                {
 
149
                neg = true;
 
150
                number = -number;
 
151
                }
 
152
                
 
153
        for (int n = 1; number; ++n)
 
154
                {
 
155
                *--p = (char) (number % 10) + '0';
 
156
                number /= 10;
 
157
                                
 
158
                if (number && (n % 3 == 0))
 
159
                        *--p = ',';
 
160
                }
 
161
        
 
162
        if (neg)
 
163
                *--p = '-';
 
164
                
 
165
        return JString(p);
 
166
}