1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "cachemapobject1.hxx"
21 #include "cachemapobject2.hxx"
22 #include "cachemapobject3.hxx"
23 #include "cachemapobjectcontainer2.hxx"
26 #include "rtl/ref.hxx"
27 #include "rtl/ustring.hxx"
31 #include <stdio.h> // <iostream> or <cstdio> do not work well on all platforms
33 using ucb::cachemap::Object1
;
34 using ucb::cachemap::Object2
;
35 using ucb::cachemap::Object3
;
36 using ucb::cachemap::ObjectContainer1
;
37 using ucb::cachemap::ObjectContainer2
;
38 using ucb::cachemap::ObjectContainer3
;
42 // Give template function a dummy parameter, to work around MSVC++ bug:
43 template< typename Cont
, typename ContRef
, typename Obj
>
44 sal_uInt32
test(Obj
*)
46 ContRef
xCont(new Cont
);
47 OUString
aPrefix("key");
48 sal_uInt32 nTimer
= osl_getGlobalTimer();
49 for (int i
= 0; i
< 100000; i
+= 5)
53 + OUString::valueOf(static_cast< sal_Int32
>(
55 rtl::Reference
< Obj
> xObj01(xCont
->get(aKey0
));
56 for (int j
= 0; j
< 50; ++j
)
58 rtl::Reference
< Obj
> xRef(xObj01
);
60 rtl::Reference
< Obj
> xObj02(xCont
->get(aKey0
));
61 for (int j
= 0; j
< 50; ++j
)
63 rtl::Reference
< Obj
> xRef(xObj02
);
68 + OUString::valueOf(static_cast< sal_Int32
>(
70 rtl::Reference
< Obj
> xObj11(xCont
->get(aKey1
));
71 for (int j
= 0; j
< 50; ++j
)
73 rtl::Reference
< Obj
> xRef(xObj11
);
75 rtl::Reference
< Obj
> xObj12(xCont
->get(aKey1
));
76 for (int j
= 0; j
< 50; ++j
)
78 rtl::Reference
< Obj
> xRef(xObj12
);
83 + OUString::valueOf(static_cast< sal_Int32
>(
85 rtl::Reference
< Obj
> xObj21(xCont
->get(aKey2
));
86 for (int j
= 0; j
< 50; ++j
)
88 rtl::Reference
< Obj
> xRef(xObj21
);
90 rtl::Reference
< Obj
> xObj22(xCont
->get(aKey2
));
91 for (int j
= 0; j
< 50; ++j
)
93 rtl::Reference
< Obj
> xRef(xObj22
);
98 + OUString::valueOf(static_cast< sal_Int32
>(
100 rtl::Reference
< Obj
> xObj31(xCont
->get(aKey3
));
101 for (int j
= 0; j
< 50; ++j
)
103 rtl::Reference
< Obj
> xRef(xObj31
);
105 rtl::Reference
< Obj
> xObj32(xCont
->get(aKey3
));
106 for (int j
= 0; j
< 50; ++j
)
108 rtl::Reference
< Obj
> xRef(xObj32
);
113 + OUString::valueOf(static_cast< sal_Int32
>(
115 rtl::Reference
< Obj
> xObj41(xCont
->get(aKey4
));
116 for (int j
= 0; j
< 50; ++j
)
118 rtl::Reference
< Obj
> xRef(xObj41
);
120 rtl::Reference
< Obj
> xObj42(xCont
->get(aKey4
));
121 for (int j
= 0; j
< 50; ++j
)
123 rtl::Reference
< Obj
> xRef(xObj42
);
126 return osl_getGlobalTimer() - nTimer
;
133 // Use the second set of measurements, to avoid startup inaccuracies:
134 for (int i
= 0; i
< 2; ++i
)
135 printf("Version 1: %lu ms.\nVersion 2: %lu ms.\nVersion 3: %lu ms.\n",
136 static_cast< unsigned long >(
137 test
< ObjectContainer1
,
138 rtl::Reference
< ObjectContainer1
>,
140 static_cast< unsigned long >(
141 test
< ObjectContainer2
,
142 std::auto_ptr
< ObjectContainer2
>,
144 static_cast< unsigned long >(
145 test
< ObjectContainer3
,
146 rtl::Reference
< ObjectContainer3
>,
151 // unxsols3.pro: Version 1: 9137 ms.
152 // Version 2: 8634 ms.
153 // Version 3: 3166 ms.
155 // wntmsci7.pro: Version 1: 3846 ms.
156 // Version 2: 5598 ms.
157 // Version 3: 2704 ms.
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */