[multiple changes]
authorBenjamin Kosnik <bkoz@gcc.gnu.org>
Thu, 5 Feb 2004 01:33:07 +0000 (01:33 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Thu, 5 Feb 2004 01:33:07 +0000 (01:33 +0000)
2004-02-04  Felix Yen  <fwy@alumni.brown.edu>

* testsuite/performance/20_util/producer_consumer.cc: New.
* testsuite/performance/20_util/allocator/insert_insert.cc: Two loops.

2004-02-04  Benjamin Kosnik  <bkoz@redhat.com>

* testsuite/performance/20_util/allocator.cc: Move to..
* testsuite/performance/20_util/allocator/insert.cc: ...here.
* testsuite/performance/20_util/allocator_thread.cc: Move to...
* testsuite/performance/20_util/allocator/insert_insert.cc: ...here.
* testsuite/performance/20_util/allocator_map_thread.cc: Move to...
* testsuite/performance/20_util/allocator/map_thread.cc: ...here.

From-SVN: r77285

libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/performance/20_util/allocator.cc [deleted file]
libstdc++-v3/testsuite/performance/20_util/allocator/insert.cc [new file with mode: 0644]
libstdc++-v3/testsuite/performance/20_util/allocator/insert_insert.cc [new file with mode: 0644]
libstdc++-v3/testsuite/performance/20_util/allocator/map_thread.cc [new file with mode: 0644]
libstdc++-v3/testsuite/performance/20_util/allocator/producer_consumer.cc [new file with mode: 0644]
libstdc++-v3/testsuite/performance/20_util/allocator_map_thread.cc [deleted file]
libstdc++-v3/testsuite/performance/20_util/allocator_thread.cc [deleted file]

index 564fe304db331641acf017c562dcbc6d56084982..1a5a989a826725c01ce8ac9f7a484a28b4683664 100644 (file)
@@ -1,3 +1,17 @@
+2004-02-04  Felix Yen  <fwy@alumni.brown.edu>
+
+       * testsuite/performance/20_util/producer_consumer.cc: New.
+       * testsuite/performance/20_util/allocator/insert_insert.cc: Two loops.
+       
+2004-02-04  Benjamin Kosnik  <bkoz@redhat.com>
+       
+       * testsuite/performance/20_util/allocator.cc: Move to..
+       * testsuite/performance/20_util/allocator/insert.cc: ...here.   
+       * testsuite/performance/20_util/allocator_thread.cc: Move to...
+       * testsuite/performance/20_util/allocator/insert_insert.cc: ...here.
+       * testsuite/performance/20_util/allocator_map_thread.cc: Move to...
+       * testsuite/performance/20_util/allocator/map_thread.cc: ...here.
+       
 2004-02-04  Jonathan Wakely  <redi@gcc.gnu.org>
 
        * docs/html/faq/index.html: Recommend using LD_LIBRARY_PATH.
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator.cc b/libstdc++-v3/testsuite/performance/20_util/allocator.cc
deleted file mode 100644 (file)
index 7a27c2f..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING.  If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/*
- * The goal with this application is to compare the performance
- * between different std::allocator implementations. The results are
- * influenced by the underlying allocator in the "C" library, malloc.
- */
-
-// 2003-02-05 Stefan Olsson <stefan@snon.net>
-
-#include <vector>
-#include <list>
-#include <map>
-#include <deque>
-#include <set>
-#include <typeinfo>
-#include <sstream>
-#include <ext/mt_allocator.h>
-#include <ext/new_allocator.h>
-#include <ext/malloc_allocator.h>
-#include <cxxabi.h>
-#include <testsuite_performance.h>
-
-using namespace std;
-
-typedef int test_type;
-
-// The number of iterations to be performed.
-int iterations = 100000;
-
-// The number of values to insert in the container, 32 will cause 5
-// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
-// This means that all allocations are within _MAX_BYTES = 128 as
-// defined in stl_alloc.h for __pool_alloc.  Whether or not this
-// value is relevant in "the real world" or not I don't know and
-// should probably be investigated in more detail.
-int insert_values = 128;
-
-template<typename TestType>
-  struct value_type : public pair<TestType, TestType>
-  {
-    value_type() : pair<TestType, TestType>(0, 0) { }
-
-    inline value_type operator++() { return ++this->first, *this; }
-    inline operator TestType() const { return this->first; }
-  };
-
-template<typename Container>
-  int
-  do_loop(Container& obj)
-  {
-    int test_iterations = 0;
-    try
-      {
-       value_type<test_type> test_value;
-       while (test_iterations < iterations)
-         {
-           for (int j = 0; j < insert_values; ++j)
-             obj.insert(obj.end(), ++test_value);
-           ++test_iterations;
-         }
-      }
-    catch(...)
-      {
-       // No point allocating all available memory, repeatedly.        
-      }
-    return test_iterations;
-  }
-
-template<typename Container>
-  void
-  test_container(Container obj)
-  {
-    using namespace __gnu_test;
-    int status;
-
-    time_counter time;
-    resource_counter resource;
-    clear_counters(time, resource);
-    start_counters(time, resource);
-    int test_iterations = do_loop(obj);
-    stop_counters(time, resource);
-    std::ostringstream comment;
-    comment << "iterations: " << test_iterations << '\t';
-    comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
-                                              0, 0, &status);
-    report_header(__FILE__, comment.str());
-    report_performance(__FILE__, string(), time, resource);
-  }
-
-// http://gcc.gnu.org/ml/libstdc++/2001-05/msg00105.html
-// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
-int main(void)
-{
-  typedef __gnu_cxx::malloc_allocator<test_type> m_alloc_type;
-  typedef __gnu_cxx::new_allocator<test_type> n_alloc_type;
-  typedef __gnu_cxx::__mt_alloc<test_type> so_alloc_type;
-
-#ifdef TEST_B0
-  test_container(vector<test_type, m_alloc_type>());
-#endif
-#ifdef TEST_B1
-  test_container(vector<test_type, n_alloc_type>());
-#endif
-#ifdef TEST_B2
-  test_container(vector<test_type, so_alloc_type>());
-#endif
-
-#ifdef TEST_B3
-  test_container(list<test_type, m_alloc_type>());
-#endif
-#ifdef TEST_B4
-  test_container(list<test_type, n_alloc_type>());
-#endif
-#ifdef TEST_B5
-  test_container(list<test_type, so_alloc_type>());
-#endif
-
-#ifdef TEST_B6
-  test_container(deque<test_type, m_alloc_type>());
-#endif
-#ifdef TEST_B7
-  test_container(deque<test_type, n_alloc_type>());
-#endif
-#ifdef TEST_B8
-  test_container(deque<test_type, so_alloc_type>());
-#endif
-
-  typedef less<test_type> compare_type;
-#ifdef TEST_B9
-  test_container(map<test_type, test_type, compare_type, m_alloc_type>());
-#endif
-#ifdef TEST_B10
-  test_container(map<test_type, test_type, compare_type, n_alloc_type>());
-#endif
-#ifdef TEST_B11
-  test_container(map<test_type, test_type, compare_type, so_alloc_type>());
-#endif
-
-#ifdef TEST_B12
-  test_container(set<test_type, compare_type, m_alloc_type>());
-#endif
-#ifdef TEST_B13
-  test_container(set<test_type, compare_type, n_alloc_type>());
-#endif
-#ifdef TEST_B14
-  test_container(set<test_type, compare_type, so_alloc_type>());
-#endif
-
-  return 0;
-}
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator/insert.cc b/libstdc++-v3/testsuite/performance/20_util/allocator/insert.cc
new file mode 100644 (file)
index 0000000..7a27c2f
--- /dev/null
@@ -0,0 +1,177 @@
+// Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/*
+ * The goal with this application is to compare the performance
+ * between different std::allocator implementations. The results are
+ * influenced by the underlying allocator in the "C" library, malloc.
+ */
+
+// 2003-02-05 Stefan Olsson <stefan@snon.net>
+
+#include <vector>
+#include <list>
+#include <map>
+#include <deque>
+#include <set>
+#include <typeinfo>
+#include <sstream>
+#include <ext/mt_allocator.h>
+#include <ext/new_allocator.h>
+#include <ext/malloc_allocator.h>
+#include <cxxabi.h>
+#include <testsuite_performance.h>
+
+using namespace std;
+
+typedef int test_type;
+
+// The number of iterations to be performed.
+int iterations = 100000;
+
+// The number of values to insert in the container, 32 will cause 5
+// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
+// This means that all allocations are within _MAX_BYTES = 128 as
+// defined in stl_alloc.h for __pool_alloc.  Whether or not this
+// value is relevant in "the real world" or not I don't know and
+// should probably be investigated in more detail.
+int insert_values = 128;
+
+template<typename TestType>
+  struct value_type : public pair<TestType, TestType>
+  {
+    value_type() : pair<TestType, TestType>(0, 0) { }
+
+    inline value_type operator++() { return ++this->first, *this; }
+    inline operator TestType() const { return this->first; }
+  };
+
+template<typename Container>
+  int
+  do_loop(Container& obj)
+  {
+    int test_iterations = 0;
+    try
+      {
+       value_type<test_type> test_value;
+       while (test_iterations < iterations)
+         {
+           for (int j = 0; j < insert_values; ++j)
+             obj.insert(obj.end(), ++test_value);
+           ++test_iterations;
+         }
+      }
+    catch(...)
+      {
+       // No point allocating all available memory, repeatedly.        
+      }
+    return test_iterations;
+  }
+
+template<typename Container>
+  void
+  test_container(Container obj)
+  {
+    using namespace __gnu_test;
+    int status;
+
+    time_counter time;
+    resource_counter resource;
+    clear_counters(time, resource);
+    start_counters(time, resource);
+    int test_iterations = do_loop(obj);
+    stop_counters(time, resource);
+    std::ostringstream comment;
+    comment << "iterations: " << test_iterations << '\t';
+    comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
+                                              0, 0, &status);
+    report_header(__FILE__, comment.str());
+    report_performance(__FILE__, string(), time, resource);
+  }
+
+// http://gcc.gnu.org/ml/libstdc++/2001-05/msg00105.html
+// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
+int main(void)
+{
+  typedef __gnu_cxx::malloc_allocator<test_type> m_alloc_type;
+  typedef __gnu_cxx::new_allocator<test_type> n_alloc_type;
+  typedef __gnu_cxx::__mt_alloc<test_type> so_alloc_type;
+
+#ifdef TEST_B0
+  test_container(vector<test_type, m_alloc_type>());
+#endif
+#ifdef TEST_B1
+  test_container(vector<test_type, n_alloc_type>());
+#endif
+#ifdef TEST_B2
+  test_container(vector<test_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_B3
+  test_container(list<test_type, m_alloc_type>());
+#endif
+#ifdef TEST_B4
+  test_container(list<test_type, n_alloc_type>());
+#endif
+#ifdef TEST_B5
+  test_container(list<test_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_B6
+  test_container(deque<test_type, m_alloc_type>());
+#endif
+#ifdef TEST_B7
+  test_container(deque<test_type, n_alloc_type>());
+#endif
+#ifdef TEST_B8
+  test_container(deque<test_type, so_alloc_type>());
+#endif
+
+  typedef less<test_type> compare_type;
+#ifdef TEST_B9
+  test_container(map<test_type, test_type, compare_type, m_alloc_type>());
+#endif
+#ifdef TEST_B10
+  test_container(map<test_type, test_type, compare_type, n_alloc_type>());
+#endif
+#ifdef TEST_B11
+  test_container(map<test_type, test_type, compare_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_B12
+  test_container(set<test_type, compare_type, m_alloc_type>());
+#endif
+#ifdef TEST_B13
+  test_container(set<test_type, compare_type, n_alloc_type>());
+#endif
+#ifdef TEST_B14
+  test_container(set<test_type, compare_type, so_alloc_type>());
+#endif
+
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator/insert_insert.cc b/libstdc++-v3/testsuite/performance/20_util/allocator/insert_insert.cc
new file mode 100644 (file)
index 0000000..c5df36a
--- /dev/null
@@ -0,0 +1,198 @@
+// Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/*
+ * The goal with this application is to compare the performance
+ * between different std::allocator implementations. The results are
+ * influenced by the underlying allocator in the "C" library, malloc.
+ */
+
+// 2003-02-05 Stefan Olsson <stefan@snon.net>
+
+#include <vector>
+#include <list>
+#include <map>
+#include <deque>
+#include <set>
+#include <typeinfo>
+#include <sstream>
+#include <pthread.h>
+#include <ext/mt_allocator.h>
+#include <ext/new_allocator.h>
+#include <ext/malloc_allocator.h>
+#include <cxxabi.h>
+#include <testsuite_performance.h>
+
+using namespace std;
+
+typedef int test_type;
+
+// The number of iterations to be performed.
+int iterations = 25000;
+
+// The number of values to insert in the container, 32 will cause 5
+// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
+// This means that all allocations are within _MAX_BYTES = 128 as
+// defined in stl_alloc.h for __pool_alloc.  Whether or not this
+// value is relevant in "the real world" or not I don't know and
+// should probably be investigated in more detail.
+int insert_values = 128;
+
+template<typename TestType>
+  struct value_type : public pair<TestType, TestType>
+  {
+    value_type() : pair<TestType, TestType>(0, 0) { }
+
+    inline value_type operator++() { return ++this->first, *this; }
+    inline operator TestType() const { return this->first; }
+  };
+
+template<typename Container>
+  void
+  do_loop()
+  {
+    Container obj;
+    int test_iterations = 0;
+    value_type<test_type> test_value;
+    while (test_iterations < iterations)
+      {
+       for (int j = 0; j < insert_values; ++j)
+         obj.insert(obj.end(), ++test_value);
+       ++test_iterations;
+      }
+  }
+
+template<typename Container>
+  void*
+  do_test(void* p = NULL)
+  {
+    try
+      {
+       do_loop<Container>();
+       do_loop<Container>();
+      }
+    catch(...)
+      {
+       // No point allocating all available memory, repeatedly.
+      }
+  }
+
+template<typename Container>
+  void
+  test_container(Container obj)
+  {
+    using namespace __gnu_test;
+    int status;
+
+    time_counter time;
+    resource_counter resource;
+
+    clear_counters(time, resource);
+    start_counters(time, resource);
+    
+    pthread_t  t1, t2, t3, t4;
+    pthread_create(&t1, 0, &do_test<Container>, 0);
+    pthread_create(&t2, 0, &do_test<Container>, 0);
+    pthread_create(&t3, 0, &do_test<Container>, 0);
+    pthread_create(&t4, 0, &do_test<Container>, 0);
+
+    pthread_join(t1, NULL);
+    pthread_join(t2, NULL);
+    pthread_join(t3, NULL);
+    pthread_join(t4, NULL);
+
+    stop_counters(time, resource);
+    std::ostringstream comment;
+    comment << "iterations: " << iterations << '\t';
+    comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
+                                              0, 0, &status);
+    report_header(__FILE__, comment.str());
+    report_performance(__FILE__, string(), time, resource);
+  }
+
+// http://gcc.gnu.org/ml/libstdc++/2001-05/msg00105.html
+// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
+int main(void)
+{
+  typedef __gnu_cxx::malloc_allocator<test_type> m_alloc_type;
+  typedef __gnu_cxx::new_allocator<test_type> n_alloc_type;
+  typedef __gnu_cxx::__mt_alloc<test_type> so_alloc_type;
+
+#ifdef TEST_T0
+  test_container(vector<test_type, m_alloc_type>());
+#endif
+#ifdef TEST_T1
+  test_container(vector<test_type, n_alloc_type>());
+#endif
+#ifdef TEST_T2
+  test_container(vector<test_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_T3
+  test_container(list<test_type, m_alloc_type>());
+#endif
+#ifdef TEST_T4
+  test_container(list<test_type, n_alloc_type>());
+#endif
+#ifdef TEST_T5
+  test_container(list<test_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_T6
+  test_container(deque<test_type, m_alloc_type>());
+#endif
+#ifdef TEST_T7
+  test_container(deque<test_type, n_alloc_type>());
+#endif
+#ifdef TEST_T8
+  test_container(deque<test_type, so_alloc_type>());
+#endif
+
+  typedef less<test_type> compare_type;
+#ifdef TEST_T9
+  test_container(map<test_type, test_type, compare_type, m_alloc_type>());
+#endif
+#ifdef TEST_T10
+  test_container(map<test_type, test_type, compare_type, n_alloc_type>());
+#endif
+#ifdef TEST_T11
+  test_container(map<test_type, test_type, compare_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_T12
+  test_container(set<test_type, compare_type, m_alloc_type>());
+#endif
+#ifdef TEST_T13
+  test_container(set<test_type, compare_type, n_alloc_type>());
+#endif
+#ifdef TEST_T14
+  test_container(set<test_type, compare_type, so_alloc_type>());
+#endif
+
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator/map_thread.cc b/libstdc++-v3/testsuite/performance/20_util/allocator/map_thread.cc
new file mode 100644 (file)
index 0000000..f6b4d45
--- /dev/null
@@ -0,0 +1,125 @@
+// Copyright (C) 2004 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/*
+ * The goal with this application is to compare the performance
+ * between different std::allocator implementations. The results are
+ * influenced by the underlying allocator in the "C" library, malloc.
+ */
+
+// libstdc++/13823 recast for this testing framework
+
+#include <map>
+#include <iostream>
+#include <typeinfo>
+#include <sstream>
+#include <ext/mt_allocator.h>
+#include <ext/new_allocator.h>
+#include <ext/malloc_allocator.h>
+#include <cxxabi.h>
+#include <testsuite_performance.h>
+
+using namespace std;
+using __gnu_cxx::__mt_alloc;
+using __gnu_cxx::new_allocator;
+using __gnu_cxx::malloc_allocator;
+
+// The number of iterations to be performed.
+int iterations = 25000;
+
+template<typename Container>
+  void*
+  do_loop(void* p = NULL)
+  {
+    try
+      {
+       for (int c = 0; c < 10; c++)
+         {
+           Container m;
+
+           for (unsigned i = 0; i < iterations; ++i) 
+             m[i] = i;
+         }
+      }
+    catch(...)
+      {
+       // No point allocating all available memory, repeatedly.        
+      }
+  }
+
+template<typename Container>
+  void
+  test_container(Container obj)
+  {
+    using namespace __gnu_test;
+    int status;
+
+    time_counter time;
+    resource_counter resource;
+
+    clear_counters(time, resource);
+    start_counters(time, resource);
+    
+    pthread_t  t1, t2, t3, t4;
+    pthread_create(&t1, NULL, &do_loop<Container>, NULL);
+    pthread_create(&t2, NULL, &do_loop<Container>, NULL);
+    pthread_create(&t3, NULL, &do_loop<Container>, NULL);
+    pthread_create(&t4, NULL, &do_loop<Container>, NULL);
+
+    pthread_join(t1, NULL);
+    pthread_join(t2, NULL);
+    pthread_join(t3, NULL);
+    pthread_join(t4, NULL);
+
+    stop_counters(time, resource);
+    std::ostringstream comment;
+    comment << "iterations: " << iterations << '\t';
+    comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
+                                              0, 0, &status);
+    report_header(__FILE__, comment.str());
+    report_performance(__FILE__, string(), time, resource);
+  }
+
+int main(void)
+{
+#ifdef TEST_T1
+  test_container(map<int, int>());
+#endif
+#ifdef TEST_T2
+  test_container(map<int, int, less<const int>, new_allocator<int> >());
+#endif
+#ifdef TEST_T3
+  test_container(map<int, int, less<const int>, malloc_allocator<int> >());
+#endif
+#ifdef TEST_T4
+  test_container(map<int, int, less<const int>,
+                     __mt_alloc< pair<const int, int> > >());
+#endif
+
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator/producer_consumer.cc b/libstdc++-v3/testsuite/performance/20_util/allocator/producer_consumer.cc
new file mode 100644 (file)
index 0000000..c8d2f1d
--- /dev/null
@@ -0,0 +1,318 @@
+// Copyright (C) 2004 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/*
+ * The goal with this application is to compare the performance of
+ * different allocators in a simple producer-consumer scenario.
+ */
+
+// 2004-02-04 Felix Yen <fwy@alumni.brown.edu>
+
+#include <vector>
+#include <list>
+#include <map>
+#include <typeinfo>
+#include <sstream>
+#include <pthread.h>
+#include <ext/mt_allocator.h>
+#include <ext/new_allocator.h>
+#include <ext/malloc_allocator.h>
+#include <cxxabi.h>
+#include <testsuite_performance.h>
+
+
+using namespace std;
+using __gnu_cxx::__mt_alloc;
+using __gnu_cxx::new_allocator;
+using __gnu_cxx::malloc_allocator;
+using abi::__cxa_demangle;
+
+typedef int test_type;
+typedef less<test_type> compare_type;
+typedef malloc_allocator<test_type> malloc_alloc_type;
+typedef new_allocator<test_type> new_alloc_type;
+typedef __mt_alloc<test_type> so_alloc_type;
+
+// The number of iterations to be performed.
+int iterations = 25000;
+
+// TODO - restore Stefan's comment?  i don't understand it.  -- fwy
+int insert_values = 128;
+
+class Lock
+{
+public:
+  Lock() {pthread_mutex_init(&mutex, 0);}
+  ~Lock() {pthread_mutex_destroy(&mutex);}
+
+public:
+  inline pthread_mutex_t* operator&() {return &mutex;}
+
+public:
+  inline void lock() {pthread_mutex_lock(&mutex);}
+  inline void unlock() {pthread_mutex_unlock(&mutex);}
+
+private:
+  Lock(const Lock&);
+  Lock& operator=(Lock&);
+
+private:
+  pthread_mutex_t mutex;
+};
+
+class AutoLock
+{
+public:
+  AutoLock(Lock& _lock)
+  : lock(_lock)
+  {lock.lock();}
+
+  ~AutoLock() {lock.unlock();}
+
+private:
+  AutoLock(AutoLock&);
+  AutoLock& operator=(AutoLock&);
+
+private:
+  Lock& lock;
+};
+
+template<typename Container>
+  class Queue
+  {
+  public:
+    Queue() {pthread_cond_init(&condition, 0);}
+    ~Queue() {pthread_cond_destroy(&condition);}
+
+  public:
+    void push_back(const typename Container::value_type& x);
+    void swap(Container& container);
+
+  private:
+    pthread_cond_t condition;
+    Lock lock;
+    Container queue;
+  };
+
+template<typename Container>
+  void
+  Queue<Container>::push_back(const typename Container::value_type& value)
+  {
+    AutoLock auto_lock(lock);
+    queue.insert(queue.end(), value);
+    if (queue.size() == 1) pthread_cond_signal(&condition);
+  }
+
+template<typename Container>
+  void
+  Queue<Container>::swap(Container& container)
+  {
+    AutoLock auto_lock(lock);
+    while (queue.empty()) pthread_cond_wait(&condition, &lock);
+    queue.swap(container);
+  }
+
+class Thread
+{ 
+  // NB: Make this the last data member of an object defining operator()().
+public:
+  class Attributes
+  {
+  public:
+    Attributes(int state = PTHREAD_CREATE_JOINABLE);
+    ~Attributes() {pthread_attr_destroy(&attributes);}
+
+  public:
+    inline pthread_attr_t* operator&() {return &attributes;}
+
+  private:
+    pthread_attr_t attributes;
+  };
+
+public:
+  Thread() {thread = pthread_self();}
+  ~Thread();
+
+public:
+  template <typename ThreadOwner>
+    void create(ThreadOwner* owner);
+
+private:
+  pthread_t thread;
+};
+
+Thread::Attributes::Attributes(int state)
+{
+  pthread_attr_init(&attributes);
+  pthread_attr_setdetachstate(&attributes, state);
+}
+
+Thread::~Thread()
+{
+  if (!pthread_equal(thread, pthread_self()))
+    pthread_join(thread, 0);
+}
+
+template<typename ThreadOwner>
+  void*
+  create_thread(void* _this)
+  {
+    ThreadOwner* owner = static_cast<ThreadOwner*>(_this);
+    (*owner)();
+    return 0;
+  }
+
+template<typename ThreadOwner>
+  void
+  Thread::create(ThreadOwner* owner)
+  {
+    Thread::Attributes attributes;
+    pthread_create(&thread, &attributes, create_thread<ThreadOwner>, owner);
+  }
+
+template<typename Container>
+  class Consumer
+  {
+  public:
+    Consumer(Queue<Container>& _queue)
+    : queue(_queue)
+    {thread.create(this);}
+
+  public:
+    void operator()();
+
+  private:
+    Queue<Container>& queue;
+    Thread thread;
+  };
+
+template<typename Container>
+  void
+  Consumer<Container>::operator()()
+  {
+    for (int j = insert_values * iterations; j > 0;)
+    {
+      Container container;
+      queue.swap(container);
+      j -= container.size();
+    }
+  }
+
+template<typename TestType>
+  struct Value : public pair<TestType, TestType>
+  {
+    Value()
+    : pair<TestType, TestType>(0, 0)
+    { }
+
+    inline Value operator++() {return ++this->first, *this;}
+    inline operator TestType() const {return this->first;}
+  };
+
+template<typename Container>
+  class ProducerConsumer : private Queue<Container>
+  {
+  public:
+    ProducerConsumer() {thread.create(this);}
+  public:
+    void operator()();
+
+  private:
+    Thread thread;
+  };
+
+template<typename Container>
+  void
+  ProducerConsumer<Container>::operator()()
+  {
+    Consumer<Container> consumer(*this);
+    Value<test_type> test_value;
+    for (int j = insert_values * iterations; j-- > 0;)
+      this->push_back(++test_value);
+  }
+
+template<typename Container>
+  void
+  test_container(Container obj)
+  {
+    using namespace __gnu_test;
+    int status;
+
+    time_counter time;
+    resource_counter resource;
+
+    clear_counters(time, resource);
+    start_counters(time, resource);
+    {
+      ProducerConsumer<Container> pc1;
+      ProducerConsumer<Container> pc2;
+    }
+    stop_counters(time, resource);
+
+    std::ostringstream comment;
+    comment << "iterations: " << iterations << '\t';
+    comment << "type: " << __cxa_demangle(typeid(obj).name(), 0, 0, &status);
+    report_header(__FILE__, comment.str());
+    report_performance(__FILE__, string(), time, resource);
+  }
+
+int main(void)
+{
+#ifdef TEST_T1
+  test_container(vector<test_type, malloc_alloc_type>());
+#endif
+#ifdef TEST_T2
+  test_container(vector<test_type, new_alloc_type>());
+#endif
+#ifdef TEST_T3
+  test_container(vector<test_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_T5
+  test_container(list<test_type, malloc_alloc_type>());
+#endif
+#ifdef TEST_T6
+  test_container(list<test_type, new_alloc_type>());
+#endif
+#ifdef TEST_T7
+  test_container(list<test_type, so_alloc_type>());
+#endif
+
+#ifdef TEST_T9
+  test_container(map<test_type, test_type, compare_type, malloc_alloc_type>());
+#endif
+#ifdef TEST_T10
+  test_container(map<test_type, test_type, compare_type, new_alloc_type>());
+#endif
+#ifdef TEST_T11
+  test_container(map<test_type, test_type, compare_type, so_alloc_type>());
+#endif
+
+  return 0;
+}
+
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator_map_thread.cc b/libstdc++-v3/testsuite/performance/20_util/allocator_map_thread.cc
deleted file mode 100644 (file)
index f6b4d45..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright (C) 2004 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING.  If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/*
- * The goal with this application is to compare the performance
- * between different std::allocator implementations. The results are
- * influenced by the underlying allocator in the "C" library, malloc.
- */
-
-// libstdc++/13823 recast for this testing framework
-
-#include <map>
-#include <iostream>
-#include <typeinfo>
-#include <sstream>
-#include <ext/mt_allocator.h>
-#include <ext/new_allocator.h>
-#include <ext/malloc_allocator.h>
-#include <cxxabi.h>
-#include <testsuite_performance.h>
-
-using namespace std;
-using __gnu_cxx::__mt_alloc;
-using __gnu_cxx::new_allocator;
-using __gnu_cxx::malloc_allocator;
-
-// The number of iterations to be performed.
-int iterations = 25000;
-
-template<typename Container>
-  void*
-  do_loop(void* p = NULL)
-  {
-    try
-      {
-       for (int c = 0; c < 10; c++)
-         {
-           Container m;
-
-           for (unsigned i = 0; i < iterations; ++i) 
-             m[i] = i;
-         }
-      }
-    catch(...)
-      {
-       // No point allocating all available memory, repeatedly.        
-      }
-  }
-
-template<typename Container>
-  void
-  test_container(Container obj)
-  {
-    using namespace __gnu_test;
-    int status;
-
-    time_counter time;
-    resource_counter resource;
-
-    clear_counters(time, resource);
-    start_counters(time, resource);
-    
-    pthread_t  t1, t2, t3, t4;
-    pthread_create(&t1, NULL, &do_loop<Container>, NULL);
-    pthread_create(&t2, NULL, &do_loop<Container>, NULL);
-    pthread_create(&t3, NULL, &do_loop<Container>, NULL);
-    pthread_create(&t4, NULL, &do_loop<Container>, NULL);
-
-    pthread_join(t1, NULL);
-    pthread_join(t2, NULL);
-    pthread_join(t3, NULL);
-    pthread_join(t4, NULL);
-
-    stop_counters(time, resource);
-    std::ostringstream comment;
-    comment << "iterations: " << iterations << '\t';
-    comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
-                                              0, 0, &status);
-    report_header(__FILE__, comment.str());
-    report_performance(__FILE__, string(), time, resource);
-  }
-
-int main(void)
-{
-#ifdef TEST_T1
-  test_container(map<int, int>());
-#endif
-#ifdef TEST_T2
-  test_container(map<int, int, less<const int>, new_allocator<int> >());
-#endif
-#ifdef TEST_T3
-  test_container(map<int, int, less<const int>, malloc_allocator<int> >());
-#endif
-#ifdef TEST_T4
-  test_container(map<int, int, less<const int>,
-                     __mt_alloc< pair<const int, int> > >());
-#endif
-
-  return 0;
-}
diff --git a/libstdc++-v3/testsuite/performance/20_util/allocator_thread.cc b/libstdc++-v3/testsuite/performance/20_util/allocator_thread.cc
deleted file mode 100644 (file)
index b46ee4d..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-//
-// This file is part of the GNU ISO C++ Library.  This library is free
-// software; you can redistribute it and/or modify it under the
-// terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
-// any later version.
-
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING.  If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
-
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
-
-/*
- * The goal with this application is to compare the performance
- * between different std::allocator implementations. The results are
- * influenced by the underlying allocator in the "C" library, malloc.
- */
-
-// 2003-02-05 Stefan Olsson <stefan@snon.net>
-
-#include <vector>
-#include <list>
-#include <map>
-#include <deque>
-#include <set>
-#include <typeinfo>
-#include <sstream>
-#include <pthread.h>
-#include <ext/mt_allocator.h>
-#include <ext/new_allocator.h>
-#include <ext/malloc_allocator.h>
-#include <cxxabi.h>
-#include <testsuite_performance.h>
-
-using namespace std;
-
-typedef int test_type;
-
-// The number of iterations to be performed.
-int iterations = 25000;
-
-// The number of values to insert in the container, 32 will cause 5
-// (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
-// This means that all allocations are within _MAX_BYTES = 128 as
-// defined in stl_alloc.h for __pool_alloc.  Whether or not this
-// value is relevant in "the real world" or not I don't know and
-// should probably be investigated in more detail.
-int insert_values = 128;
-
-template<typename TestType>
-  struct value_type : public pair<TestType, TestType>
-  {
-    value_type() : pair<TestType, TestType>(0, 0) { }
-
-    inline value_type operator++() { return ++this->first, *this; }
-    inline operator TestType() const { return this->first; }
-  };
-
-template<typename Container>
-  void*
-  do_loop(void* p = NULL)
-  {
-    Container obj;    
-    try
-      {
-       int test_iterations = 0;
-       value_type<test_type> test_value;
-       while (test_iterations < iterations)
-         {
-           for (int j = 0; j < insert_values; ++j)
-             obj.insert(obj.end(), ++test_value);
-           ++test_iterations;
-         }
-       // NB: Don't use clear() here, instead force deallocation.
-        obj = Container();
-       test_iterations = 0;
-       test_value = value_type<test_type>();
-       while (test_iterations < iterations)
-         {
-           for (int j = 0; j < insert_values; ++j)
-             obj.insert(obj.end(), ++test_value);
-           ++test_iterations;
-         }
-      }
-    catch(...)
-      {
-       // No point allocating all available memory, repeatedly.        
-      }
-  }
-
-template<typename Container>
-  void
-  test_container(Container obj)
-  {
-    using namespace __gnu_test;
-    int status;
-
-    time_counter time;
-    resource_counter resource;
-
-    clear_counters(time, resource);
-    start_counters(time, resource);
-    
-    pthread_t  t1, t2, t3, t4;
-    pthread_create(&t1, 0, &do_loop<Container>, 0);
-    pthread_create(&t2, 0, &do_loop<Container>, 0);
-    pthread_create(&t3, 0, &do_loop<Container>, 0);
-    pthread_create(&t4, 0, &do_loop<Container>, 0);
-
-    pthread_join(t1, NULL);
-    pthread_join(t2, NULL);
-    pthread_join(t3, NULL);
-    pthread_join(t4, NULL);
-
-    stop_counters(time, resource);
-    std::ostringstream comment;
-    comment << "iterations: " << iterations << '\t';
-    comment << "type: " << abi::__cxa_demangle(typeid(obj).name(),
-                                              0, 0, &status);
-    report_header(__FILE__, comment.str());
-    report_performance(__FILE__, string(), time, resource);
-  }
-
-// http://gcc.gnu.org/ml/libstdc++/2001-05/msg00105.html
-// http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
-int main(void)
-{
-  typedef __gnu_cxx::malloc_allocator<test_type> m_alloc_type;
-  typedef __gnu_cxx::new_allocator<test_type> n_alloc_type;
-  typedef __gnu_cxx::__mt_alloc<test_type> so_alloc_type;
-
-#ifdef TEST_T0
-  test_container(vector<test_type, m_alloc_type>());
-#endif
-#ifdef TEST_T1
-  test_container(vector<test_type, n_alloc_type>());
-#endif
-#ifdef TEST_T2
-  test_container(vector<test_type, so_alloc_type>());
-#endif
-
-#ifdef TEST_T3
-  test_container(list<test_type, m_alloc_type>());
-#endif
-#ifdef TEST_T4
-  test_container(list<test_type, n_alloc_type>());
-#endif
-#ifdef TEST_T5
-  test_container(list<test_type, so_alloc_type>());
-#endif
-
-#ifdef TEST_T6
-  test_container(deque<test_type, m_alloc_type>());
-#endif
-#ifdef TEST_T7
-  test_container(deque<test_type, n_alloc_type>());
-#endif
-#ifdef TEST_T8
-  test_container(deque<test_type, so_alloc_type>());
-#endif
-
-  typedef less<test_type> compare_type;
-#ifdef TEST_T9
-  test_container(map<test_type, test_type, compare_type, m_alloc_type>());
-#endif
-#ifdef TEST_T10
-  test_container(map<test_type, test_type, compare_type, n_alloc_type>());
-#endif
-#ifdef TEST_T11
-  test_container(map<test_type, test_type, compare_type, so_alloc_type>());
-#endif
-
-#ifdef TEST_T12
-  test_container(set<test_type, compare_type, m_alloc_type>());
-#endif
-#ifdef TEST_T13
-  test_container(set<test_type, compare_type, n_alloc_type>());
-#endif
-#ifdef TEST_T14
-  test_container(set<test_type, compare_type, so_alloc_type>());
-#endif
-
-  return 0;
-}