1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_registry.hxx"
26
27 #include <iostream>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <time.h>
31 #include <sys/timeb.h>
32 #include <sys/types.h>
33
34 #include "registry/registry.h"
35 #include <rtl/ustring.hxx>
36 #include <rtl/alloc.h>
37
38 using namespace std;
39
40 /*****************************************************************
41 MyTimer
42 *****************************************************************/
43 #ifndef UNX
44 class MyTimer
45 {
46 public:
start()47 void start() { _ftime( &m_start ); };
stop()48 void stop()
49 {
50 _ftime( &m_stop );
51 m_diff = difftime(m_stop.time, m_start.time);
52 if (m_stop.millitm > m_start.millitm)
53 {
54 m_diff += ((double)(m_stop.millitm - m_start.millitm)) / 1000;
55 }
56 else
57 {
58 m_diff -= 1;
59 m_diff += ((double)(1000 - (m_start.millitm - m_stop.millitm))) / 1000;
60 }
61 printf(" %.4f Sekunden\n", m_diff);
62 };
63
64 protected:
65 #ifdef OS2
66 struct timeb m_start, m_stop;
67 #else
68 struct _timeb m_start, m_stop;
69 #endif
70 double m_diff;
71 };
72 #else
73 extern "C" int ftime(struct timeb *pt);
74
75 class MyTimer
76 {
77 public:
start()78 void start() { ftime( &m_start ); };
stop()79 void stop()
80 {
81 ftime( &m_stop );
82 m_diff = difftime(m_stop.time, m_start.time);
83 if (m_stop.millitm > m_start.millitm)
84 {
85 m_diff += ((double)(m_stop.millitm - m_start.millitm)) / 1000;
86 }
87 else
88 {
89 m_diff -= 1;
90 m_diff += ((double)(1000 - (m_start.millitm - m_stop.millitm))) / 1000;
91 }
92 printf(" %.4f Sekunden\n", m_diff);
93 };
94
95 protected:
96 struct timeb m_start, m_stop;
97 double m_diff;
98 };
99 #endif
100
101 using namespace rtl;
102
103 #if (defined UNX) || (defined OS2)
main(int argc,char * argv[])104 int main( int argc, char * argv[] )
105 #else
106 int _cdecl main( int argc, char * argv[] )
107 #endif
108 {
109 RegHandle hReg;
110 RegKeyHandle hRootKey, hKey, hSubKey, hSubSubKey;
111 OUString sName1(RTL_CONSTASCII_USTRINGPARAM("regkey"));
112 OUString sName2(RTL_CONSTASCII_USTRINGPARAM("regSubkey"));
113 OUString sName3(RTL_CONSTASCII_USTRINGPARAM("regSubSubkey"));
114 OUString keyName1;
115 OUString keyName2;
116 OUString keyName3;
117 int S1 = 10;
118 int S2 = 10;
119 int S3 = 10;
120 MyTimer aTimer;
121
122 if (argc < 4)
123 {
124 cerr << "using regspeed count1 count2 count3\n";
125 exit(1);
126 }
127
128 S1 = atoi(argv[1]);
129 S2 = atoi(argv[2]);
130 S3 = atoi(argv[3]);
131
132 OUString speedReg( RTL_CONSTASCII_USTRINGPARAM("speed.reg"));
133 if (reg_createRegistry(speedReg.pData, &hReg))
134 {
135 cout << "creating registry \"test.reg\" failed\n";
136 } else
137 {
138 if (reg_openRootKey(hReg, &hRootKey))
139 {
140 cout << "open root key \"test.reg\" failed\n";
141 } else
142 {
143 printf("\n %d keys anlegen, oeffnen und schliessen dauert ... ", (S1 * S2 * S3));
144 aTimer.start();
145
146 for (sal_Int32 i=0; i < S1; i++)
147 {
148 keyName1 = sName1;
149 keyName1 += OUString().valueOf(i);
150 if (reg_createKey(hRootKey, keyName1.pData, &hKey))
151 cout << "creating key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
152 << "\" failed\n";
153
154 for (sal_Int32 j=0; j < S2; j++)
155 {
156 keyName2 = sName2;
157 keyName2 += OUString().valueOf(j);
158 if (reg_createKey(hKey, keyName2.pData, &hSubKey))
159 cout << "creating key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
160 << "\" failed\n";
161
162 for (sal_Int32 n=0; n < S3; n++)
163 {
164 keyName3 = sName3;
165 keyName3 += OUString().valueOf(n);
166 if (reg_createKey(hSubKey, keyName3.pData, &hSubSubKey))
167 cout << "creating key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
168 << "\" failed\n";
169
170 if (reg_closeKey(hSubSubKey))
171 cout << "closing key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
172 << "\" failed\n";
173 }
174
175 if (reg_closeKey(hSubKey))
176 cout << "closing key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
177 << "\" failed\n";
178 }
179
180 if (reg_closeKey(hKey))
181 cout << "closing key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
182 << "\" failed\n";
183 }
184
185 aTimer.stop();
186
187 printf("\n %d keys oeffnen und schliessen dauert ... ", (S1 * S2 * S3));
188 aTimer.start();
189
190 for (sal_Int32 i=0; i < S1; i++)
191 {
192 keyName1 = OUString::createFromAscii("/");
193 keyName1 += sName1;
194 keyName1 += OUString().valueOf(i);
195 if (reg_openKey(hRootKey, keyName1.pData, &hKey))
196 cout << "open key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
197 << "\" failed\n";
198
199 for (sal_Int32 j=0; j < S2; j++)
200 {
201 keyName2 = OUString::createFromAscii("/");
202 keyName2 += sName1;
203 keyName2 += OUString().valueOf(i);
204 keyName2 += OUString::createFromAscii("/");
205 keyName2 += sName2;
206 keyName2 += OUString().valueOf(j);
207 if (reg_openKey(hRootKey, keyName2.pData, &hSubKey))
208 cout << "open key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
209 << "\" failed\n";
210
211 for (sal_Int32 n=0; n < S3; n++)
212 {
213 keyName3 = OUString::createFromAscii("/");
214 keyName3 += sName1;
215 keyName3 += OUString().valueOf(i);
216 keyName3 += OUString::createFromAscii("/");
217 keyName3 += sName2;
218 keyName3 += OUString().valueOf(j);
219 keyName3 += OUString::createFromAscii("/");
220 keyName3 += sName3;
221 keyName3 += OUString().valueOf(n);
222 if (reg_openKey(hRootKey, keyName3.pData, &hSubSubKey))
223 cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
224 << "\" failed\n";
225
226 if (reg_closeKey(hSubSubKey))
227 cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
228 << "\" failed\n";
229 }
230
231 if (reg_closeKey(hSubKey))
232 cout << "closing key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
233 << "\" failed\n";
234 }
235
236 if (reg_closeKey(hKey))
237 cout << "closing key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
238 << "\" failed\n";
239 }
240
241 aTimer.stop();
242
243 printf("\n 1 key oeffnen und schliessen dauert ... ");
244 aTimer.start();
245
246 if (reg_openKey(hRootKey, keyName3.pData, &hSubSubKey))
247 cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
248 << "\" failed\n";
249
250 if (reg_closeKey(hSubSubKey))
251 cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
252 << "\" failed\n";
253
254 aTimer.stop();
255
256 }
257
258 if (reg_closeKey(hRootKey))
259 cout << "closing root key failed\n";
260 if (reg_closeRegistry(hReg))
261 cout << "\t41. closing registry \"test.reg\" failed\n";
262 }
263
264 return(0);
265 }
266
267
268