]> git.saurik.com Git - wxWidgets.git/commitdiff
add TLS access benchmark
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 8 Aug 2008 00:43:20 +0000 (00:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 8 Aug 2008 00:43:20 +0000 (00:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55015 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/benchmarks/Makefile.in
tests/benchmarks/bench.bkl
tests/benchmarks/bench.dsp
tests/benchmarks/bench.h
tests/benchmarks/bench.vcproj
tests/benchmarks/makefile.bcc
tests/benchmarks/makefile.gcc
tests/benchmarks/makefile.vc
tests/benchmarks/makefile.wat
tests/benchmarks/tls.cpp [new file with mode: 0644]

index 9160871cb217da2633c778ccb53fa8a9fa5f14b3..92058a3b53daf9c4243e3d8397133b97ce11b496 100644 (file)
@@ -44,7 +44,8 @@ BENCH_CXXFLAGS = -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
        $(CXXFLAGS)
 BENCH_OBJECTS =  \
        bench_bench.o \
-       bench_strings.o
+       bench_strings.o \
+       bench_tls.o
 
 ### Conditionally set variables: ###
 
@@ -111,6 +112,9 @@ bench_bench.o: $(srcdir)/bench.cpp
 bench_strings.o: $(srcdir)/strings.cpp
        $(CXXC) -c -o $@ $(BENCH_CXXFLAGS) $(srcdir)/strings.cpp
 
+bench_tls.o: $(srcdir)/tls.cpp
+       $(CXXC) -c -o $@ $(BENCH_CXXFLAGS) $(srcdir)/tls.cpp
+
 
 $(srcdir)/include/wx/stc/stc.h: \
 $(srcdir)/src/stc/scintilla/include/Scintilla.iface \
index 9107e459e7509d3afb496cf046413489e9d00e33..d8016412aafd1e98de25969cfc1ffe6ac721bca7 100644 (file)
@@ -12,6 +12,7 @@
         <sources>
             bench.cpp
             strings.cpp
+            tls.cpp
         </sources>
         <wx-lib>base</wx-lib>
     </exe>
index 795a9ce8e4ae19b4811288e633de24207d556d1c..65dec996de79c4b59f8a5a5fddc290dc25d1f018 100644 (file)
@@ -241,6 +241,10 @@ SOURCE=.\bench.cpp
 \r
 SOURCE=.\strings.cpp\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\tls.cpp\r
+# End Source File\r
 # End Group\r
 # End Target\r
 # End Project\r
index af7fba2723cba19b151128feeeb39a9ee546fba4..96a9a1fc8c7ff4239d1691a5cccedc180a0174cf 100644 (file)
@@ -12,6 +12,7 @@
 #define _WX_TESTS_BENCHMARKS_BENCH_H_
 
 #include "wx/cpp.h"
+#include "wx/defs.h"
 
 namespace Bench
 {
index cb31b290c8712754219c3b41c470aabda6095372..dc6e68e116533a21391f69392371f7d71e0c968a 100644 (file)
                        <File\r
                                RelativePath=".\strings.cpp"\r
                        />\r
+                       <File\r
+                               RelativePath=".\tls.cpp"\r
+                       />\r
                </Filter>\r
        </Files>\r
        <Globals>\r
index 38987c9ce57bd9cde73d93211cde9ba4184cb6f6..a11072feef15c58f91b7bd54847555066de5a025 100644 (file)
@@ -36,7 +36,8 @@ BENCH_CXXFLAGS = $(__RUNTIME_LIBS_7) -I$(BCCDIR)\include $(__DEBUGINFO) \
        -DwxUSE_GUI=0 $(CPPFLAGS) $(CXXFLAGS)
 BENCH_OBJECTS =  \
        $(OBJS)\bench_bench.obj \
-       $(OBJS)\bench_strings.obj
+       $(OBJS)\bench_strings.obj \
+       $(OBJS)\bench_tls.obj
 
 ### Conditionally set variables: ###
 
@@ -194,3 +195,6 @@ $(OBJS)\bench_bench.obj: .\bench.cpp
 $(OBJS)\bench_strings.obj: .\strings.cpp
        $(CXX) -q -c -P -o$@ $(BENCH_CXXFLAGS) .\strings.cpp
 
+$(OBJS)\bench_tls.obj: .\tls.cpp
+       $(CXX) -q -c -P -o$@ $(BENCH_CXXFLAGS) .\tls.cpp
+
index 20cc9a78fc174f0412fe884fb452f77b1361fc7c..4da2fb6fb1042701e8cb939884037f8a69b30c5d 100644 (file)
@@ -29,7 +29,8 @@ BENCH_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG) \
        -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
 BENCH_OBJECTS =  \
        $(OBJS)\bench_bench.o \
-       $(OBJS)\bench_strings.o
+       $(OBJS)\bench_strings.o \
+       $(OBJS)\bench_tls.o
 
 ### Conditionally set variables: ###
 
@@ -184,6 +185,9 @@ $(OBJS)\bench_bench.o: ./bench.cpp
 $(OBJS)\bench_strings.o: ./strings.cpp
        $(CXX) -c -o $@ $(BENCH_CXXFLAGS) $(CPPDEPS) $<
 
+$(OBJS)\bench_tls.o: ./tls.cpp
+       $(CXX) -c -o $@ $(BENCH_CXXFLAGS) $(CPPDEPS) $<
+
 .PHONY: all clean
 
 
index cf37916d83df3acbf6fe85c1c8311ab14c50bee5..d6a3a3cf7ba7828c27bdc1b27de81351b5f5c7bd 100644 (file)
@@ -30,7 +30,8 @@ BENCH_CXXFLAGS = /M$(__RUNTIME_LIBS_8)$(__DEBUGRUNTIME_3) /DWIN32 \
        $(CXXFLAGS)
 BENCH_OBJECTS =  \
        $(OBJS)\bench_bench.obj \
-       $(OBJS)\bench_strings.obj
+       $(OBJS)\bench_strings.obj \
+       $(OBJS)\bench_tls.obj
 
 ### Conditionally set variables: ###
 
@@ -251,3 +252,6 @@ $(OBJS)\bench_bench.obj: .\bench.cpp
 $(OBJS)\bench_strings.obj: .\strings.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(BENCH_CXXFLAGS) .\strings.cpp
 
+$(OBJS)\bench_tls.obj: .\tls.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(BENCH_CXXFLAGS) .\tls.cpp
+
index 29e865b960bebd1aaf9dbf9fa6d48414861751ed..feb639f5c2c693b3c9bb95478c08f2308a60a189 100644 (file)
@@ -210,7 +210,8 @@ BENCH_CXXFLAGS = $(__DEBUGINFO_0) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG_5) &
        -dwxUSE_GUI=0 $(__RTTIFLAG_7) $(__EXCEPTIONSFLAG_8) $(CPPFLAGS) $(CXXFLAGS)
 BENCH_OBJECTS =  &
        $(OBJS)\bench_bench.obj &
-       $(OBJS)\bench_strings.obj
+       $(OBJS)\bench_strings.obj &
+       $(OBJS)\bench_tls.obj
 
 
 all : $(OBJS)
@@ -247,3 +248,6 @@ $(OBJS)\bench_bench.obj :  .AUTODEPEND .\bench.cpp
 $(OBJS)\bench_strings.obj :  .AUTODEPEND .\strings.cpp
        $(CXX) -bt=nt -zq -fo=$^@ $(BENCH_CXXFLAGS) $<
 
+$(OBJS)\bench_tls.obj :  .AUTODEPEND .\tls.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(BENCH_CXXFLAGS) $<
+
diff --git a/tests/benchmarks/tls.cpp b/tests/benchmarks/tls.cpp
new file mode 100644 (file)
index 0000000..afccef5
--- /dev/null
@@ -0,0 +1,127 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        tests/benchmarks/strings.cpp
+// Purpose:     String-related benchmarks
+// Author:      Vadim Zeitlin
+// Created:     2008-07-19
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#include "bench.h"
+
+#ifdef __UNIX__
+    #define HAVE_PTHREAD
+    #include <pthread.h>
+#endif
+
+#if wxCHECK_GCC_VERSION(3, 3)
+    #define HAVE_COMPILER_THREAD
+    #define wxTHREAD_SPECIFIC __thread
+#endif
+
+// uncomment this to also test Boost version (you will also need to link with
+// libboost_threads)
+//#define HAVE_BOOST_THREAD
+#ifdef HAVE_BOOST_THREAD
+    #include <boost/thread/tss.hpp>
+#endif
+
+
+static const int NUM_ITER = 1000;
+
+// this is just a baseline
+BENCHMARK_FUNC(DummyTLS)
+{
+    static int s_global = 0;
+
+    for ( int n = 0; n < NUM_ITER; n++ )
+    {
+        if ( n % 2 )
+            s_global = 0;
+        else
+            s_global = n;
+    }
+
+    return !s_global;
+}
+
+#ifdef HAVE_COMPILER_THREAD
+
+BENCHMARK_FUNC(CompilerTLS)
+{
+    static wxTHREAD_SPECIFIC int s_global = 0;
+
+    for ( int n = 0; n < NUM_ITER; n++ )
+    {
+        if ( n % 2 )
+            s_global = 0;
+        else
+            s_global = n;
+    }
+
+    return !s_global;
+}
+
+#endif // HAVE_COMPILER_THREAD
+
+#ifdef HAVE_PTHREAD
+
+class PthreadKey
+{
+public:
+    PthreadKey()
+    {
+        pthread_key_create(&m_key, NULL);
+    }
+
+    ~PthreadKey()
+    {
+        pthread_key_delete(m_key);
+    }
+
+    operator pthread_key_t() const { return m_key; }
+
+private:
+    pthread_key_t m_key;
+
+    DECLARE_NO_COPY_CLASS(PthreadKey)
+};
+
+BENCHMARK_FUNC(PosixTLS)
+{
+    static PthreadKey s_key;
+
+    for ( int n = 0; n < NUM_ITER; n++ )
+    {
+        if ( n % 2 )
+            pthread_setspecific(s_key, 0);
+        else
+            pthread_setspecific(s_key, &n);
+    }
+
+    return !pthread_getspecific(s_key);
+}
+
+#endif // HAVE_PTHREAD
+
+#ifdef HAVE_BOOST_THREAD
+
+BENCHMARK_FUNC(BoostTLS)
+{
+    static boost::thread_specific_ptr<int> s_ptr;
+    if ( !s_ptr.get() )
+        s_ptr.reset(new int(0));
+
+    for ( int n = 0; n < NUM_ITER; n++ )
+    {
+        if ( n % 2 )
+            *s_ptr = 0;
+        else
+            *s_ptr = n;
+    }
+
+    return !*s_ptr;
+}
+
+#endif // HAVE_BOOST_THREAD