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