xref: /aoo41x/main/registry/workben/regspeed.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_registry.hxx"
30 
31 #include <iostream>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <time.h>
35 #include <sys/timeb.h>
36 #include <sys/types.h>
37 
38 #include "registry/registry.h"
39 #include	<rtl/ustring.hxx>
40 #include	<rtl/alloc.h>
41 
42 using namespace std;
43 
44 /*****************************************************************
45 	MyTimer
46 *****************************************************************/
47 #ifndef UNX
48 class MyTimer
49 {
50 public:
51 	void start() { _ftime( &m_start ); };
52 	void stop()
53 	{
54 		_ftime( &m_stop );
55 		m_diff = difftime(m_stop.time, m_start.time);
56 		if (m_stop.millitm > m_start.millitm)
57 		{
58 			m_diff += ((double)(m_stop.millitm - m_start.millitm)) / 1000;
59 		}
60 		else
61 		{
62 			m_diff -= 1;
63 			m_diff += ((double)(1000 - (m_start.millitm - m_stop.millitm))) / 1000;
64 		}
65 		printf(" %.4f Sekunden\n", m_diff);
66 	};
67 
68 protected:
69 #ifdef OS2
70 	struct timeb m_start, m_stop;
71 #else
72 	struct _timeb m_start, m_stop;
73 #endif
74 	double m_diff;
75 };
76 #else
77 extern "C" int ftime(struct timeb *pt);
78 
79 class MyTimer
80 {
81 public:
82 	void start() { ftime( &m_start ); };
83 	void stop()
84 	{
85 		ftime( &m_stop );
86 		m_diff = difftime(m_stop.time, m_start.time);
87 		if (m_stop.millitm > m_start.millitm)
88 		{
89 			m_diff += ((double)(m_stop.millitm - m_start.millitm)) / 1000;
90 		}
91 		else
92 		{
93 			m_diff -= 1;
94 			m_diff += ((double)(1000 - (m_start.millitm - m_stop.millitm))) / 1000;
95 		}
96 		printf(" %.4f Sekunden\n", m_diff);
97 	};
98 
99 protected:
100 	struct timeb m_start, m_stop;
101 	double m_diff;
102 };
103 #endif
104 
105 using namespace rtl;
106 
107 #if (defined UNX) || (defined OS2)
108 int main( int argc, char * argv[] )
109 #else
110 int _cdecl main( int argc, char * argv[] )
111 #endif
112 {
113 	RegHandle 		hReg;
114 	RegKeyHandle	hRootKey, hKey, hSubKey, hSubSubKey;
115 	OUString 		sName1(RTL_CONSTASCII_USTRINGPARAM("regkey"));
116 	OUString 		sName2(RTL_CONSTASCII_USTRINGPARAM("regSubkey"));
117 	OUString 		sName3(RTL_CONSTASCII_USTRINGPARAM("regSubSubkey"));
118 	OUString 		keyName1;
119 	OUString 		keyName2;
120 	OUString 		keyName3;
121 	int 			S1 = 10;
122 	int 			S2 = 10;
123 	int 			S3 = 10;
124 	MyTimer			aTimer;
125 
126 	if (argc < 4)
127 	{
128 		cerr << "using regspeed count1 count2 count3\n";
129 		exit(1);
130 	}
131 
132 	S1 = atoi(argv[1]);
133 	S2 = atoi(argv[2]);
134 	S3 = atoi(argv[3]);
135 
136 	OUString speedReg( RTL_CONSTASCII_USTRINGPARAM("speed.reg"));
137 	if (reg_createRegistry(speedReg.pData, &hReg))
138 	{
139 		cout << "creating registry \"test.reg\" failed\n";
140 	} else
141 	{
142 		if (reg_openRootKey(hReg, &hRootKey))
143 		{
144 			cout << "open root key \"test.reg\" failed\n";
145 		} else
146 		{
147 			printf("\n %d keys anlegen, oeffnen und schliessen dauert ... ", (S1 * S2 * S3));
148 			aTimer.start();
149 
150 			for (sal_Int32 i=0; i < S1; i++)
151 			{
152 				keyName1 = sName1;
153 				keyName1 += OUString().valueOf(i);
154 				if (reg_createKey(hRootKey, keyName1.pData, &hKey))
155 					cout << "creating key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
156 						 << "\" failed\n";
157 
158 				for (sal_Int32 j=0; j < S2; j++)
159 				{
160 					keyName2 = sName2;
161 					keyName2 += OUString().valueOf(j);
162 					if (reg_createKey(hKey, keyName2.pData, &hSubKey))
163 						cout << "creating key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
164 							 << "\" failed\n";
165 
166 						for (sal_Int32 n=0; n < S3; n++)
167 						{
168 							keyName3 = sName3;
169 							keyName3 += OUString().valueOf(n);
170 							if (reg_createKey(hSubKey, keyName3.pData, &hSubSubKey))
171 								cout << "creating key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
172 									 << "\" failed\n";
173 
174 							if (reg_closeKey(hSubSubKey))
175 								cout << "closing key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
176 									 << "\" failed\n";
177 						}
178 
179 					if (reg_closeKey(hSubKey))
180 						cout << "closing key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
181 							 << "\" failed\n";
182 				}
183 
184 				if (reg_closeKey(hKey))
185 					cout << "closing key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
186 						 << "\" failed\n";
187 			}
188 
189 			aTimer.stop();
190 
191 			printf("\n %d keys oeffnen und schliessen dauert ... ", (S1 * S2 * S3));
192 			aTimer.start();
193 
194 			for (sal_Int32 i=0; i < S1; i++)
195 			{
196 				keyName1 = OUString::createFromAscii("/");
197 				keyName1 += sName1;
198 				keyName1 += OUString().valueOf(i);
199 				if (reg_openKey(hRootKey, keyName1.pData, &hKey))
200 					cout << "open key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
201 						 << "\" failed\n";
202 
203 				for (sal_Int32 j=0; j < S2; j++)
204 				{
205 					keyName2 = OUString::createFromAscii("/");
206 					keyName2 += sName1;
207 					keyName2 += OUString().valueOf(i);
208 					keyName2 += OUString::createFromAscii("/");
209 					keyName2 += sName2;
210 					keyName2 += OUString().valueOf(j);
211 					if (reg_openKey(hRootKey, keyName2.pData, &hSubKey))
212 						cout << "open key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
213 							 << "\" failed\n";
214 
215 						for (sal_Int32 n=0; n < S3; n++)
216 						{
217 							keyName3 = OUString::createFromAscii("/");
218 							keyName3 += sName1;
219 							keyName3 += OUString().valueOf(i);
220 							keyName3 += OUString::createFromAscii("/");
221 							keyName3 += sName2;
222 							keyName3 += OUString().valueOf(j);
223 							keyName3 += OUString::createFromAscii("/");
224 							keyName3 += sName3;
225 							keyName3 += OUString().valueOf(n);
226 							if (reg_openKey(hRootKey, keyName3.pData, &hSubSubKey))
227 								cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
228 									 << "\" failed\n";
229 
230 							if (reg_closeKey(hSubSubKey))
231 								cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
232 									 << "\" failed\n";
233 						}
234 
235 					if (reg_closeKey(hSubKey))
236 						cout << "closing key \"" << OUStringToOString(keyName2, RTL_TEXTENCODING_ASCII_US).getStr()
237 							 << "\" failed\n";
238 				}
239 
240 				if (reg_closeKey(hKey))
241 					cout << "closing key \"" << OUStringToOString(keyName1, RTL_TEXTENCODING_ASCII_US).getStr()
242 						 << "\" failed\n";
243 			}
244 
245 			aTimer.stop();
246 
247 			printf("\n 1 key oeffnen und schliessen dauert ... ");
248 			aTimer.start();
249 
250 			if (reg_openKey(hRootKey, keyName3.pData, &hSubSubKey))
251 				cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
252 					 << "\" failed\n";
253 
254 			if (reg_closeKey(hSubSubKey))
255 				cout << "open key \"" << OUStringToOString(keyName3, RTL_TEXTENCODING_ASCII_US).getStr()
256 					 << "\" failed\n";
257 
258 			aTimer.stop();
259 
260 		}
261 
262 		if (reg_closeKey(hRootKey))
263 			cout << "closing root key failed\n";
264 		if (reg_closeRegistry(hReg))
265 			cout << "\t41. closing registry \"test.reg\" failed\n";
266 	}
267 
268 	return(0);
269 }
270 
271 
272