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