merge the formfield patch from ooo-build
[ooovba.git] / bridges / test / performance / testperformance.cxx
blob6fa5d77159c2c2aca77347671108516f0411c24e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testperformance.cxx,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_bridges.hxx"
35 #include <stdio.h>
36 #include <math.h>
38 #include <osl/interlck.h>
39 #include <osl/mutex.hxx>
40 #include <osl/semaphor.h>
42 #include <rtl/string.hxx>
43 #include <rtl/byteseq.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
47 #ifdef SAL_W32
48 #include <windows.h>
49 #else
50 #include <sys/times.h>
51 #endif
52 #ifndef ULONG_MAX
53 #define ULONG_MAX 0xffffffff
54 #endif
56 using namespace ::rtl;
57 using namespace ::osl;
58 using namespace ::com::sun::star::uno;
60 static inline sal_uInt32 getSystemTicks()
62 #ifdef SAL_W32
63 return (sal_uInt32)GetTickCount();
64 #else // only UNX supported for now
65 static sal_uInt32 nImplTicksPerSecond = 0;
66 static double dImplTicksPerSecond;
67 static double dImplTicksULONGMAX;
69 struct tms aTms;
70 sal_uInt32 nTicks = (sal_uInt32)times( &aTms );
72 if ( !nImplTicksPerSecond )
74 nImplTicksPerSecond = CLK_TCK;
75 dImplTicksPerSecond = nImplTicksPerSecond;
76 dImplTicksULONGMAX = (double)(sal_uInt32)ULONG_MAX;
79 double fTicks = nTicks;
80 fTicks *= 1000;
81 fTicks /= dImplTicksPerSecond;
82 fTicks = fmod (fTicks, dImplTicksULONGMAX);
84 return (sal_uInt32)fTicks;
85 #endif
88 class MyTimer
90 public:
91 MyTimer( const OString &descString ) :
92 nStart( getSystemTicks() ),
93 m_descString( descString )
96 ~MyTimer( )
98 printf( "%f s : %s\n", (getSystemTicks() -nStart) / 1000., m_descString.getStr() );
100 private:
101 sal_uInt32 nStart;
102 OString m_descString;
105 void main()
107 // interlocked count
109 MyTimer timer( "performance - 1000*10000 interlocked count" );
110 oslInterlockedCount count;
111 for( int i = 0 ; i < 1000*10000 ; i ++ )
113 osl_incrementInterlockedCount( &count );
117 OString myDummyString( "blubber" );
118 MyTimer timer( "performance - 1000*10000 acquiring/releasing a refcounted string(without destruction)" );
119 for( int i = 0 ; i < 1000*10000 ; i ++ )
121 OString myNextDummyString = myDummyString ;
125 printf( "--------------------\n" );
127 Mutex mutex;
128 MyTimer timer( "performance - 1000*10000 acquiring/releasing an osl::Mutex" );
129 for( int i = 0 ; i < 1000*10000 ; i ++ )
131 MutexGuard guard( mutex );
136 oslSemaphore sema = osl_createSemaphore(1);
137 MyTimer timer( "performance - 1000*10000 acquiring/releasing an osl::Semaphore" );
138 for( int i = 0 ; i < 1000*10000 ; i ++ )
140 osl_acquireSemaphore( sema );
141 osl_releaseSemaphore( sema );
145 printf( "--------------------\n" );
147 MyTimer timer( "performance - 1000*10000 rtl::ByteSequence(500)" );
148 for( int i = 0 ; i < 1000*1000 ; i ++ )
150 ByteSequence seq(500);
155 MyTimer timer( "performance - 1000*1000 rtl::ByteSequence(500,BYTESEQ_NODEFAULT)" );
156 for( int i = 0 ; i < 1000*1000 ; i ++ )
158 ByteSequence seq(500, BYTESEQ_NODEFAULT);
162 MyTimer timer( "performance - 1000*1000 com::sun::star::uno::Sequence< sal_Int8 > (500)" );
163 for( int i = 0 ; i < 1000*1000 ; i ++ )
165 Sequence< sal_Int8> seq(500);
169 MyTimer timer( "performance - 1000*1000 rtl_freeMemory( rtl_allocateMemory( 512 ) )" );
170 for( int i = 0 ; i < 1000*1000 ; i ++ )
172 rtl_freeMemory( rtl_allocateMemory( 512 ) );
176 printf( "--------------------\n" );
178 MyTimer timer( "performance - 1000*1000 byte string construction/destruction" );
179 for( int i = 0 ; i < 1000*1000 ; i ++ )
181 OString textEnc( "this is a test string" );
186 MyTimer timer( "performance - 1000*1000 unicode string construction/destruction" );
187 for( int i = 0 ; i < 1000*1000 ; i ++ )
189 OUString textEnc( RTL_CONSTASCII_USTRINGPARAM( "this is a test string" ) );