1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tests/benchmarks/strings.cpp
3 // Purpose: String-related benchmarks
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
18 #if wxCHECK_GCC_VERSION(3, 3)
19 #define HAVE_COMPILER_THREAD
20 #define wxTHREAD_SPECIFIC __thread
23 // uncomment this to also test Boost version (you will also need to link with
25 //#define HAVE_BOOST_THREAD
26 #ifdef HAVE_BOOST_THREAD
27 #include <boost/thread/tss.hpp>
31 static const int NUM_ITER
= 1000;
33 // this is just a baseline
34 BENCHMARK_FUNC(DummyTLS
)
36 static int s_global
= 0;
38 for ( int n
= 0; n
< NUM_ITER
; n
++ )
49 #ifdef HAVE_COMPILER_THREAD
51 BENCHMARK_FUNC(CompilerTLS
)
53 static wxTHREAD_SPECIFIC
int s_global
= 0;
55 for ( int n
= 0; n
< NUM_ITER
; n
++ )
66 #endif // HAVE_COMPILER_THREAD
75 pthread_key_create(&m_key
, NULL
);
80 pthread_key_delete(m_key
);
83 operator pthread_key_t() const { return m_key
; }
88 DECLARE_NO_COPY_CLASS(PthreadKey
)
91 BENCHMARK_FUNC(PosixTLS
)
93 static PthreadKey s_key
;
95 for ( int n
= 0; n
< NUM_ITER
; n
++ )
98 pthread_setspecific(s_key
, 0);
100 pthread_setspecific(s_key
, &n
);
103 return !pthread_getspecific(s_key
);
106 #endif // HAVE_PTHREAD
108 #ifdef HAVE_BOOST_THREAD
110 BENCHMARK_FUNC(BoostTLS
)
112 static boost
::thread_specific_ptr
<int> s_ptr
;
114 s_ptr
.reset(new int(0));
116 for ( int n
= 0; n
< NUM_ITER
; n
++ )
127 #endif // HAVE_BOOST_THREAD