1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cachemaptest.cxx,v $
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"
41 #include "rtl/ref.hxx"
42 #include "rtl/ustring.hxx"
44 #ifndef INCLUDED_CSTDLIB
46 #define INCLUDED_CSTDLIB
48 #ifndef INCLUDED_MEMORY
50 #define INCLUDED_MEMORY
52 #ifndef INCLUDED_STDIO_H
53 #include <stdio.h> // <iostream> or <cstdio> do not work well on all platforms
54 #define INCLUDED_STDIO_H
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
;
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)
77 + rtl::OUString::valueOf(static_cast< sal_Int32
>(
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
);
90 + rtl::OUString::valueOf(static_cast< sal_Int32
>(
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
);
103 + rtl::OUString::valueOf(static_cast< sal_Int32
>(
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
);
116 + rtl::OUString::valueOf(static_cast< sal_Int32
>(
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
);
129 + rtl::OUString::valueOf(static_cast< sal_Int32
>(
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
;
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
>,
154 static_cast< unsigned long >(
155 test
< ObjectContainer2
,
156 std::auto_ptr
< ObjectContainer2
>,
158 static_cast< unsigned long >(
159 test
< ObjectContainer3
,
160 rtl::Reference
< ObjectContainer3
>,
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.