1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2f86921cSAndrew Rist  * distributed with this work for additional information
6*2f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2f86921cSAndrew Rist  *
11*2f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist  *
13*2f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist  * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2f86921cSAndrew Rist  * specific language governing permissions and limitations
18*2f86921cSAndrew Rist  * under the License.
19*2f86921cSAndrew Rist  *
20*2f86921cSAndrew Rist  *************************************************************/
21*2f86921cSAndrew Rist 
22*2f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir #include "cachemapobject1.hxx"
27cdf0e10cSrcweir #include "cachemapobject2.hxx"
28cdf0e10cSrcweir #include "cachemapobject3.hxx"
29cdf0e10cSrcweir #include "cachemapobjectcontainer2.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _SOL_TIME_H_
32cdf0e10cSrcweir #include "osl/time.h"
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include "rtl/ref.hxx"
35cdf0e10cSrcweir #include "rtl/ustring.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #ifndef INCLUDED_CSTDLIB
38cdf0e10cSrcweir #include <cstdlib>
39cdf0e10cSrcweir #define INCLUDED_CSTDLIB
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef INCLUDED_MEMORY
42cdf0e10cSrcweir #include <memory>
43cdf0e10cSrcweir #define INCLUDED_MEMORY
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef INCLUDED_STDIO_H
46cdf0e10cSrcweir #include <stdio.h> // <iostream> or <cstdio> do not work well on all platforms
47cdf0e10cSrcweir #define INCLUDED_STDIO_H
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using ucb::cachemap::Object1;
51cdf0e10cSrcweir using ucb::cachemap::Object2;
52cdf0e10cSrcweir using ucb::cachemap::Object3;
53cdf0e10cSrcweir using ucb::cachemap::ObjectContainer1;
54cdf0e10cSrcweir using ucb::cachemap::ObjectContainer2;
55cdf0e10cSrcweir using ucb::cachemap::ObjectContainer3;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir namespace {
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // Give template function a dummy parameter, to work around MSVC++ bug:
60cdf0e10cSrcweir template< typename Cont, typename ContRef, typename Obj >
test(Obj *)61cdf0e10cSrcweir sal_uInt32 test(Obj *)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     ContRef xCont(new Cont);
64cdf0e10cSrcweir     rtl::OUString aPrefix(RTL_CONSTASCII_USTRINGPARAM("key"));
65cdf0e10cSrcweir     sal_uInt32 nTimer = osl_getGlobalTimer();
66cdf0e10cSrcweir     for (int i = 0; i < 100000; i += 5)
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         rtl::OUString
69cdf0e10cSrcweir             aKey0(aPrefix
70cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
71cdf0e10cSrcweir                                                    i % 100)));
72cdf0e10cSrcweir         rtl::Reference< Obj > xObj01(xCont->get(aKey0));
73cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
74cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj01);
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir         rtl::Reference< Obj > xObj02(xCont->get(aKey0));
77cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
78cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj02);
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         rtl::OUString
82cdf0e10cSrcweir             aKey1(aPrefix
83cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
84cdf0e10cSrcweir                                                    (i + 1) % 100)));
85cdf0e10cSrcweir         rtl::Reference< Obj > xObj11(xCont->get(aKey1));
86cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
87cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj11);
88cdf0e10cSrcweir         }
89cdf0e10cSrcweir         rtl::Reference< Obj > xObj12(xCont->get(aKey1));
90cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
91cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj12);
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         rtl::OUString
95cdf0e10cSrcweir             aKey2(aPrefix
96cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
97cdf0e10cSrcweir                                                    (i + 2) % 100)));
98cdf0e10cSrcweir         rtl::Reference< Obj > xObj21(xCont->get(aKey2));
99cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
100cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj21);
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir         rtl::Reference< Obj > xObj22(xCont->get(aKey2));
103cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
104cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj22);
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         rtl::OUString
108cdf0e10cSrcweir             aKey3(aPrefix
109cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
110cdf0e10cSrcweir                                                    (i + 3) % 100)));
111cdf0e10cSrcweir         rtl::Reference< Obj > xObj31(xCont->get(aKey3));
112cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
113cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj31);
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir         rtl::Reference< Obj > xObj32(xCont->get(aKey3));
116cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
117cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj32);
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         rtl::OUString
121cdf0e10cSrcweir             aKey4(aPrefix
122cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
123cdf0e10cSrcweir                                                    (i + 4) % 100)));
124cdf0e10cSrcweir         rtl::Reference< Obj > xObj41(xCont->get(aKey4));
125cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
126cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj41);
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir         rtl::Reference< Obj > xObj42(xCont->get(aKey4));
129cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
130cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj42);
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     return osl_getGlobalTimer() - nTimer;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
main()138cdf0e10cSrcweir int main()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     // Use the second set of measurements, to avoid startup inaccuracies:
141cdf0e10cSrcweir     for (int i = 0; i < 2; ++i)
142cdf0e10cSrcweir         printf("Version 1: %lu ms.\nVersion 2: %lu ms.\nVersion 3: %lu ms.\n",
143cdf0e10cSrcweir                static_cast< unsigned long >(
144cdf0e10cSrcweir                    test< ObjectContainer1,
145cdf0e10cSrcweir                          rtl::Reference< ObjectContainer1 >,
146cdf0e10cSrcweir                          Object1 >(0)),
147cdf0e10cSrcweir                static_cast< unsigned long >(
148cdf0e10cSrcweir                    test< ObjectContainer2,
149cdf0e10cSrcweir                          std::auto_ptr< ObjectContainer2 >,
150cdf0e10cSrcweir                          Object2 >(0)),
151cdf0e10cSrcweir                static_cast< unsigned long >(
152cdf0e10cSrcweir                    test< ObjectContainer3,
153cdf0e10cSrcweir                          rtl::Reference< ObjectContainer3 >,
154cdf0e10cSrcweir                          Object3 >(0)));
155cdf0e10cSrcweir     return EXIT_SUCCESS;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // unxsols3.pro: Version 1: 9137 ms.
159cdf0e10cSrcweir //               Version 2: 8634 ms.
160cdf0e10cSrcweir //               Version 3: 3166 ms.
161cdf0e10cSrcweir //
162cdf0e10cSrcweir // wntmsci7.pro: Version 1: 3846 ms.
163cdf0e10cSrcweir //               Version 2: 5598 ms.
164cdf0e10cSrcweir //               Version 3: 2704 ms.
165