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