1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_ucb.hxx"
30*cdf0e10cSrcweir #include "cachemapobject1.hxx"
31*cdf0e10cSrcweir #include "cachemapobject2.hxx"
32*cdf0e10cSrcweir #include "cachemapobject3.hxx"
33*cdf0e10cSrcweir #include "cachemapobjectcontainer2.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifndef _SOL_TIME_H_
36*cdf0e10cSrcweir #include "osl/time.h"
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #include "rtl/ref.hxx"
39*cdf0e10cSrcweir #include "rtl/ustring.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #ifndef INCLUDED_CSTDLIB
42*cdf0e10cSrcweir #include <cstdlib>
43*cdf0e10cSrcweir #define INCLUDED_CSTDLIB
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef INCLUDED_MEMORY
46*cdf0e10cSrcweir #include <memory>
47*cdf0e10cSrcweir #define INCLUDED_MEMORY
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef INCLUDED_STDIO_H
50*cdf0e10cSrcweir #include <stdio.h> // <iostream> or <cstdio> do not work well on all platforms
51*cdf0e10cSrcweir #define INCLUDED_STDIO_H
52*cdf0e10cSrcweir #endif
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using ucb::cachemap::Object1;
55*cdf0e10cSrcweir using ucb::cachemap::Object2;
56*cdf0e10cSrcweir using ucb::cachemap::Object3;
57*cdf0e10cSrcweir using ucb::cachemap::ObjectContainer1;
58*cdf0e10cSrcweir using ucb::cachemap::ObjectContainer2;
59*cdf0e10cSrcweir using ucb::cachemap::ObjectContainer3;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir namespace {
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir // Give template function a dummy parameter, to work around MSVC++ bug:
64*cdf0e10cSrcweir template< typename Cont, typename ContRef, typename Obj >
65*cdf0e10cSrcweir sal_uInt32 test(Obj *)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     ContRef xCont(new Cont);
68*cdf0e10cSrcweir     rtl::OUString aPrefix(RTL_CONSTASCII_USTRINGPARAM("key"));
69*cdf0e10cSrcweir     sal_uInt32 nTimer = osl_getGlobalTimer();
70*cdf0e10cSrcweir     for (int i = 0; i < 100000; i += 5)
71*cdf0e10cSrcweir     {
72*cdf0e10cSrcweir         rtl::OUString
73*cdf0e10cSrcweir             aKey0(aPrefix
74*cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
75*cdf0e10cSrcweir                                                    i % 100)));
76*cdf0e10cSrcweir         rtl::Reference< Obj > xObj01(xCont->get(aKey0));
77*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
78*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj01);
79*cdf0e10cSrcweir         }
80*cdf0e10cSrcweir         rtl::Reference< Obj > xObj02(xCont->get(aKey0));
81*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
82*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj02);
83*cdf0e10cSrcweir         }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir         rtl::OUString
86*cdf0e10cSrcweir             aKey1(aPrefix
87*cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
88*cdf0e10cSrcweir                                                    (i + 1) % 100)));
89*cdf0e10cSrcweir         rtl::Reference< Obj > xObj11(xCont->get(aKey1));
90*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
91*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj11);
92*cdf0e10cSrcweir         }
93*cdf0e10cSrcweir         rtl::Reference< Obj > xObj12(xCont->get(aKey1));
94*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
95*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj12);
96*cdf0e10cSrcweir         }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         rtl::OUString
99*cdf0e10cSrcweir             aKey2(aPrefix
100*cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
101*cdf0e10cSrcweir                                                    (i + 2) % 100)));
102*cdf0e10cSrcweir         rtl::Reference< Obj > xObj21(xCont->get(aKey2));
103*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
104*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj21);
105*cdf0e10cSrcweir         }
106*cdf0e10cSrcweir         rtl::Reference< Obj > xObj22(xCont->get(aKey2));
107*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
108*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj22);
109*cdf0e10cSrcweir         }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir         rtl::OUString
112*cdf0e10cSrcweir             aKey3(aPrefix
113*cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
114*cdf0e10cSrcweir                                                    (i + 3) % 100)));
115*cdf0e10cSrcweir         rtl::Reference< Obj > xObj31(xCont->get(aKey3));
116*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
117*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj31);
118*cdf0e10cSrcweir         }
119*cdf0e10cSrcweir         rtl::Reference< Obj > xObj32(xCont->get(aKey3));
120*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
121*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj32);
122*cdf0e10cSrcweir         }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         rtl::OUString
125*cdf0e10cSrcweir             aKey4(aPrefix
126*cdf0e10cSrcweir                       + rtl::OUString::valueOf(static_cast< sal_Int32 >(
127*cdf0e10cSrcweir                                                    (i + 4) % 100)));
128*cdf0e10cSrcweir         rtl::Reference< Obj > xObj41(xCont->get(aKey4));
129*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
130*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj41);
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir         rtl::Reference< Obj > xObj42(xCont->get(aKey4));
133*cdf0e10cSrcweir         {for (int j = 0; j < 50; ++j)
134*cdf0e10cSrcweir             rtl::Reference< Obj > xRef(xObj42);
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir     return osl_getGlobalTimer() - nTimer;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir int main()
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     // Use the second set of measurements, to avoid startup inaccuracies:
145*cdf0e10cSrcweir     for (int i = 0; i < 2; ++i)
146*cdf0e10cSrcweir         printf("Version 1: %lu ms.\nVersion 2: %lu ms.\nVersion 3: %lu ms.\n",
147*cdf0e10cSrcweir                static_cast< unsigned long >(
148*cdf0e10cSrcweir                    test< ObjectContainer1,
149*cdf0e10cSrcweir                          rtl::Reference< ObjectContainer1 >,
150*cdf0e10cSrcweir                          Object1 >(0)),
151*cdf0e10cSrcweir                static_cast< unsigned long >(
152*cdf0e10cSrcweir                    test< ObjectContainer2,
153*cdf0e10cSrcweir                          std::auto_ptr< ObjectContainer2 >,
154*cdf0e10cSrcweir                          Object2 >(0)),
155*cdf0e10cSrcweir                static_cast< unsigned long >(
156*cdf0e10cSrcweir                    test< ObjectContainer3,
157*cdf0e10cSrcweir                          rtl::Reference< ObjectContainer3 >,
158*cdf0e10cSrcweir                          Object3 >(0)));
159*cdf0e10cSrcweir     return EXIT_SUCCESS;
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir // unxsols3.pro: Version 1: 9137 ms.
163*cdf0e10cSrcweir //               Version 2: 8634 ms.
164*cdf0e10cSrcweir //               Version 3: 3166 ms.
165*cdf0e10cSrcweir //
166*cdf0e10cSrcweir // wntmsci7.pro: Version 1: 3846 ms.
167*cdf0e10cSrcweir //               Version 2: 5598 ms.
168*cdf0e10cSrcweir //               Version 3: 2704 ms.
169