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 .
23 #include <osl/interlck.h>
24 #include <osl/mutex.hxx>
25 #include <osl/semaphor.h>
27 #include <rtl/string.hxx>
28 #include <rtl/byteseq.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
35 #include <sys/times.h>
38 #define ULONG_MAX 0xffffffff
41 using namespace ::osl
;
42 using namespace ::com::sun::star::uno
;
44 static inline sal_uInt32
getSystemTicks()
47 return (sal_uInt32
)GetTickCount();
49 static sal_uInt32 nImplTicksPerSecond
= 0;
50 static double dImplTicksPerSecond
;
51 static double dImplTicksULONGMAX
;
54 sal_uInt32 nTicks
= (sal_uInt32
)times( &aTms
);
56 if ( !nImplTicksPerSecond
)
58 nImplTicksPerSecond
= CLK_TCK
;
59 dImplTicksPerSecond
= nImplTicksPerSecond
;
60 dImplTicksULONGMAX
= (double)(sal_uInt32
)ULONG_MAX
;
63 double fTicks
= nTicks
;
65 fTicks
/= dImplTicksPerSecond
;
66 fTicks
= fmod (fTicks
, dImplTicksULONGMAX
);
68 return (sal_uInt32
)fTicks
;
75 MyTimer( const OString
&descString
) :
76 nStart( getSystemTicks() ),
77 m_descString( descString
)
82 printf( "%f s : %s\n", (getSystemTicks() -nStart
) / 1000., m_descString
.getStr() );
93 MyTimer
timer( "performance - 1000*10000 interlocked count" );
94 oslInterlockedCount count
;
95 for( int i
= 0 ; i
< 1000*10000 ; i
++ )
97 osl_atomic_increment( &count
);
101 OString
myDummyString( "blubber" );
102 MyTimer
timer( "performance - 1000*10000 acquiring/releasing a refcounted string(without destruction)" );
103 for( int i
= 0 ; i
< 1000*10000 ; i
++ )
105 OString myNextDummyString
= myDummyString
;
109 printf( "--------------------\n" );
112 MyTimer
timer( "performance - 1000*10000 acquiring/releasing an osl::Mutex" );
113 for( int i
= 0 ; i
< 1000*10000 ; i
++ )
115 MutexGuard
guard( mutex
);
120 oslSemaphore sema
= osl_createSemaphore(1);
121 MyTimer
timer( "performance - 1000*10000 acquiring/releasing an osl::Semaphore" );
122 for( int i
= 0 ; i
< 1000*10000 ; i
++ )
124 osl_acquireSemaphore( sema
);
125 osl_releaseSemaphore( sema
);
129 printf( "--------------------\n" );
131 MyTimer
timer( "performance - 1000*10000 rtl::ByteSequence(500)" );
132 for( int i
= 0 ; i
< 1000*1000 ; i
++ )
134 ByteSequence
seq(500);
139 MyTimer
timer( "performance - 1000*1000 rtl::ByteSequence(500,BYTESEQ_NODEFAULT)" );
140 for( int i
= 0 ; i
< 1000*1000 ; i
++ )
142 ByteSequence
seq(500, BYTESEQ_NODEFAULT
);
146 MyTimer
timer( "performance - 1000*1000 com::sun::star::uno::Sequence< sal_Int8 > (500)" );
147 for( int i
= 0 ; i
< 1000*1000 ; i
++ )
149 Sequence
< sal_Int8
> seq(500);
153 MyTimer
timer( "performance - 1000*1000 rtl_freeMemory( rtl_allocateMemory( 512 ) )" );
154 for( int i
= 0 ; i
< 1000*1000 ; i
++ )
156 rtl_freeMemory( rtl_allocateMemory( 512 ) );
160 printf( "--------------------\n" );
162 MyTimer
timer( "performance - 1000*1000 byte string construction/destruction" );
163 for( int i
= 0 ; i
< 1000*1000 ; i
++ )
165 OString
textEnc( "this is a test string" );
170 MyTimer
timer( "performance - 1000*1000 unicode string construction/destruction" );
171 for( int i
= 0 ; i
< 1000*1000 ; i
++ )
173 OUString
textEnc( "this is a test string" );
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */