update dev300-m58
[ooovba.git] / ucb / workben / cachemap / cachemaptest.cxx
blob4e632de94bd507b2572a2bee3b1c86ed6acfd4bd
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: cachemaptest.cxx,v $
10 * $Revision: 1.5 $
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_ucb.hxx"
33 #include "cachemapobject1.hxx"
34 #include "cachemapobject2.hxx"
35 #include "cachemapobject3.hxx"
36 #include "cachemapobjectcontainer2.hxx"
38 #ifndef _SOL_TIME_H_
39 #include "osl/time.h"
40 #endif
41 #include "rtl/ref.hxx"
42 #include "rtl/ustring.hxx"
44 #ifndef INCLUDED_CSTDLIB
45 #include <cstdlib>
46 #define INCLUDED_CSTDLIB
47 #endif
48 #ifndef INCLUDED_MEMORY
49 #include <memory>
50 #define INCLUDED_MEMORY
51 #endif
52 #ifndef INCLUDED_STDIO_H
53 #include <stdio.h> // <iostream> or <cstdio> do not work well on all platforms
54 #define INCLUDED_STDIO_H
55 #endif
57 using ucb::cachemap::Object1;
58 using ucb::cachemap::Object2;
59 using ucb::cachemap::Object3;
60 using ucb::cachemap::ObjectContainer1;
61 using ucb::cachemap::ObjectContainer2;
62 using ucb::cachemap::ObjectContainer3;
64 namespace {
66 // Give template function a dummy parameter, to work around MSVC++ bug:
67 template< typename Cont, typename ContRef, typename Obj >
68 sal_uInt32 test(Obj *)
70 ContRef xCont(new Cont);
71 rtl::OUString aPrefix(RTL_CONSTASCII_USTRINGPARAM("key"));
72 sal_uInt32 nTimer = osl_getGlobalTimer();
73 for (int i = 0; i < 100000; i += 5)
75 rtl::OUString
76 aKey0(aPrefix
77 + rtl::OUString::valueOf(static_cast< sal_Int32 >(
78 i % 100)));
79 rtl::Reference< Obj > xObj01(xCont->get(aKey0));
80 {for (int j = 0; j < 50; ++j)
81 rtl::Reference< Obj > xRef(xObj01);
83 rtl::Reference< Obj > xObj02(xCont->get(aKey0));
84 {for (int j = 0; j < 50; ++j)
85 rtl::Reference< Obj > xRef(xObj02);
88 rtl::OUString
89 aKey1(aPrefix
90 + rtl::OUString::valueOf(static_cast< sal_Int32 >(
91 (i + 1) % 100)));
92 rtl::Reference< Obj > xObj11(xCont->get(aKey1));
93 {for (int j = 0; j < 50; ++j)
94 rtl::Reference< Obj > xRef(xObj11);
96 rtl::Reference< Obj > xObj12(xCont->get(aKey1));
97 {for (int j = 0; j < 50; ++j)
98 rtl::Reference< Obj > xRef(xObj12);
101 rtl::OUString
102 aKey2(aPrefix
103 + rtl::OUString::valueOf(static_cast< sal_Int32 >(
104 (i + 2) % 100)));
105 rtl::Reference< Obj > xObj21(xCont->get(aKey2));
106 {for (int j = 0; j < 50; ++j)
107 rtl::Reference< Obj > xRef(xObj21);
109 rtl::Reference< Obj > xObj22(xCont->get(aKey2));
110 {for (int j = 0; j < 50; ++j)
111 rtl::Reference< Obj > xRef(xObj22);
114 rtl::OUString
115 aKey3(aPrefix
116 + rtl::OUString::valueOf(static_cast< sal_Int32 >(
117 (i + 3) % 100)));
118 rtl::Reference< Obj > xObj31(xCont->get(aKey3));
119 {for (int j = 0; j < 50; ++j)
120 rtl::Reference< Obj > xRef(xObj31);
122 rtl::Reference< Obj > xObj32(xCont->get(aKey3));
123 {for (int j = 0; j < 50; ++j)
124 rtl::Reference< Obj > xRef(xObj32);
127 rtl::OUString
128 aKey4(aPrefix
129 + rtl::OUString::valueOf(static_cast< sal_Int32 >(
130 (i + 4) % 100)));
131 rtl::Reference< Obj > xObj41(xCont->get(aKey4));
132 {for (int j = 0; j < 50; ++j)
133 rtl::Reference< Obj > xRef(xObj41);
135 rtl::Reference< Obj > xObj42(xCont->get(aKey4));
136 {for (int j = 0; j < 50; ++j)
137 rtl::Reference< Obj > xRef(xObj42);
140 return osl_getGlobalTimer() - nTimer;
145 int main()
147 // Use the second set of measurements, to avoid startup inaccuracies:
148 for (int i = 0; i < 2; ++i)
149 printf("Version 1: %lu ms.\nVersion 2: %lu ms.\nVersion 3: %lu ms.\n",
150 static_cast< unsigned long >(
151 test< ObjectContainer1,
152 rtl::Reference< ObjectContainer1 >,
153 Object1 >(0)),
154 static_cast< unsigned long >(
155 test< ObjectContainer2,
156 std::auto_ptr< ObjectContainer2 >,
157 Object2 >(0)),
158 static_cast< unsigned long >(
159 test< ObjectContainer3,
160 rtl::Reference< ObjectContainer3 >,
161 Object3 >(0)));
162 return EXIT_SUCCESS;
165 // unxsols3.pro: Version 1: 9137 ms.
166 // Version 2: 8634 ms.
167 // Version 3: 3166 ms.
169 // wntmsci7.pro: Version 1: 3846 ms.
170 // Version 2: 5598 ms.
171 // Version 3: 2704 ms.