This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Work on the performance testsuite


Hi,

I have added a new test conceived by Bjarne Stroustrup, one for
the recent improvements to integer extraction, and done some
other tweaks (the formatting was quite broken ;)

Paolo.

/////////////
2003-12-16  Paolo Carlini  <pcarlini@suse.de>

	* testsuite/performance/container_benchmark.cc: New, a
	benchmark developed by Bjarne Stroustrup and Alexander
	Stepanov and made available with no restrictions.

	* testsuite/testsuite_performance.h (report_header): New,
	useful to produce header lines in the reports.
2003-12-17  Paolo Carlini  <pcarlini@suse.de>

	* testsuite/performance/container_benchmark.cc: Tweak outputs.

	* testsuite/performance/list_create_fill_sort.cc: Shrink a
	bit some outputs.

	* testsuite/testsuite_performance.h: Widen a few output fields.

	* testsuite/performance/ifstream_extract_int.cc: New.
diff -urN libstdc++-v3-orig/testsuite/performance/container_benchmark.cc libstdc++-v3/testsuite/performance/container_benchmark.cc
--- libstdc++-v3-orig/testsuite/performance/container_benchmark.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/performance/container_benchmark.cc	2003-12-16 23:14:35.000000000 +0100
@@ -0,0 +1,175 @@
+// Copyright (C) 2003 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.
+
+#include <cmath>
+#include <cstdlib>
+
+#include <vector>
+#include <algorithm>
+#include <list>
+#include <deque>
+#include <set>
+
+#include <sstream>
+#include <testsuite_performance.h>
+
+using namespace std;
+
+typedef double element_t;
+typedef void(*test)(element_t*, element_t*);
+
+void array_test(element_t* first, element_t* last)
+{
+  element_t* array = new element_t[last - first];
+  copy(first, last, array);
+  sort(array, array + (last - first));
+  unique(array, array + (last - first));
+  delete [] array;	  
+}
+
+void vector_pointer_test(element_t* first, element_t* last)
+{ 
+  vector<element_t> container(first, last);
+  sort(&*container.begin(), &*container.end());
+  unique(&*container.begin(), &*container.end());
+}
+
+void vector_iterator_test(element_t* first, element_t* last)
+{
+  vector<element_t> container(first, last);
+  sort(container.begin(), container.end());
+  unique(container.begin(), container.end());
+}
+
+void deque_test(element_t* first, element_t* last)
+{  
+  deque<element_t> container(first, last);
+  copy(first, last, container.begin()); 
+  sort(container.begin(), container.end());
+  unique(container.begin(), container.end());
+}
+    
+void list_test(element_t* first, element_t* last)
+{ 
+  list<element_t> container(first, last);
+  container.sort();
+  container.unique();
+}
+ 
+void set_test(element_t* first, element_t* last)
+{ set<element_t> container(first, last); }
+
+void multiset_test(element_t* first, element_t* last)
+{
+  multiset<element_t> container(first, last);
+  typedef multiset<element_t>::iterator iterator;
+  {
+    iterator first = container.begin();
+    iterator last = container.end();
+    
+    while (first != last)
+      {
+	iterator next = first;
+	if (++next == last) break;
+	if (*first == *next)
+	  container.erase(next);
+	else
+	  ++first;
+      }
+  }
+}
+
+double logtwo(double x)
+{ return log(x)/log(2.0); }
+
+int number_of_tests(int size)
+{
+  const double n = size;
+  const double largest_n = 1000000;
+  return int(floor((largest_n * logtwo(largest_n))
+		   / (n * logtwo(n))));
+}
+
+void initialize(element_t* first, element_t* last)
+{
+  element_t value = 0.0;
+  while (first != last)
+    {
+      *first++ = value;
+      value += 1.;
+    }
+}
+
+void run_tests(int size, const test* tests, const char** names,
+	       int ntests)
+{
+  using namespace __gnu_test;
+  time_counter time;
+  resource_counter resource;
+
+  const int n = number_of_tests(size);
+  const size_t length = 2 * size;
+
+  // make a random test set of the chosen size:
+  vector<element_t> buf(length);
+  element_t* buffer = &buf[0];
+  element_t* buffer_end = &buf[length];
+  initialize(buffer, buffer + size);	 // elements
+  initialize(buffer + size, buffer_end); // duplicate elements
+  random_shuffle(buffer, buffer_end);
+
+  // test the containers:
+  ostringstream oss;
+  oss << "size = " << size;
+  report_header(__FILE__, oss.str());
+  for (int i = 0; i < ntests; ++i)
+    {
+      start_counters(time, resource);
+      for (int j = 0; j < n; ++j)
+	tests[i](buffer, buffer_end);
+      stop_counters(time, resource);
+      report_performance(__FILE__, names[i], time, resource);
+      clear_counters(time, resource);
+    }
+}
+
+int main()
+{
+  const test tests[] = { &array_test, &vector_pointer_test,
+			 &vector_iterator_test, &deque_test,
+			 &list_test, &set_test, &multiset_test };
+  const int ntests = sizeof(tests) / sizeof(test);
+  const char* names[ntests] = { "array", "vector (ptr)",
+				"vector (iter)", "deque",
+				"list", "set", "multiset" };
+
+  const int sizes[] = {100, 1000, 10000, 100000};
+  for (int i = 0; i < sizeof(sizes) / sizeof(int); ++i)
+    run_tests(sizes[i], tests, names, ntests);
+
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/testsuite_performance.h libstdc++-v3/testsuite/testsuite_performance.h
--- libstdc++-v3-orig/testsuite/testsuite_performance.h	2003-08-08 17:24:00.000000000 +0200
+++ libstdc++-v3/testsuite/testsuite_performance.h	2003-12-16 22:58:38.000000000 +0100
@@ -197,6 +197,25 @@
     out << std::endl;
     out.close();
   }
+
+  void
+  report_header(const std::string file, const std::string header)
+  {
+    const char space = ' ';
+    const char tab = '\t';
+    const char* name = "libstdc++-performance.sum";
+    std::string::const_iterator i = file.begin() + file.find_last_of('/') + 1;
+    std::string testname(i, file.end());
+
+    std::ofstream out(name, std::ios_base::app);
+
+    out.setf(std::ios_base::left);
+    out << std::setw(25) << testname << tab;
+    out << std::setw(25) << header << tab;
+
+    out << std::endl;
+    out.close();
+  }
 }; // namespace __gnu_test
 
 #endif // _GLIBCXX_PERFORMANCE_H
diff -urN libstdc++-v3-orig/testsuite/performance/container_benchmark.cc libstdc++-v3/testsuite/performance/container_benchmark.cc
--- libstdc++-v3-orig/testsuite/performance/container_benchmark.cc	2003-12-16 23:14:35.000000000 +0100
+++ libstdc++-v3/testsuite/performance/container_benchmark.cc	2003-12-17 11:07:32.000000000 +0100
@@ -144,7 +144,7 @@
 
   // test the containers:
   ostringstream oss;
-  oss << "size = " << size;
+  oss << "size = " << size << " :";
   report_header(__FILE__, oss.str());
   for (int i = 0; i < ntests; ++i)
     {
@@ -163,8 +163,8 @@
 			 &vector_iterator_test, &deque_test,
 			 &list_test, &set_test, &multiset_test };
   const int ntests = sizeof(tests) / sizeof(test);
-  const char* names[ntests] = { "array", "vector (ptr)",
-				"vector (iter)", "deque",
+  const char* names[ntests] = { "array", "vector (pointer)",
+				"vector (iterator)", "deque",
 				"list", "set", "multiset" };
 
   const int sizes[] = {100, 1000, 10000, 100000};
diff -urN libstdc++-v3-orig/testsuite/performance/ifstream_extract_int.cc libstdc++-v3/testsuite/performance/ifstream_extract_int.cc
--- libstdc++-v3-orig/testsuite/performance/ifstream_extract_int.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/performance/ifstream_extract_int.cc	2003-12-17 10:50:23.000000000 +0100
@@ -0,0 +1,57 @@
+// Copyright (C) 2003 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.
+
+#include <fstream>
+#include <testsuite_performance.h>
+
+int main() 
+{
+  using namespace std;
+  using namespace __gnu_test;
+
+  time_counter time;
+  resource_counter resource;
+  const int iterations = 10000000;
+
+  {
+    ofstream out("tmp_perf_int.txt");
+    for (int i = 0; i < iterations; ++i)
+      out << i << "\n";
+  }
+
+  {
+    ifstream in("tmp_perf_int.txt");
+    start_counters(time, resource);  
+    for (int j, i = 0; i < iterations; ++i)
+      in >> j;
+    stop_counters(time, resource);
+    report_performance(__FILE__, "", time, resource);
+  }
+
+  unlink("tmp_perf_int.txt");
+  return 0;
+};
diff -urN libstdc++-v3-orig/testsuite/performance/list_create_fill_sort.cc libstdc++-v3/testsuite/performance/list_create_fill_sort.cc
--- libstdc++-v3-orig/testsuite/performance/list_create_fill_sort.cc	2003-07-24 23:08:03.000000000 +0200
+++ libstdc++-v3/testsuite/performance/list_create_fill_sort.cc	2003-12-17 10:01:01.000000000 +0100
@@ -57,7 +57,7 @@
       }
       stop_counters(time, resource);
 
-      sprintf(comment,"Iterations: %8u  Size: %8u",iterations,n);
+      sprintf(comment,"Iters: %8u  Size: %4u", iterations, n);
       report_performance(__FILE__, comment, time, resource);
   }
   return 0;
diff -urN libstdc++-v3-orig/testsuite/testsuite_performance.h libstdc++-v3/testsuite/testsuite_performance.h
--- libstdc++-v3-orig/testsuite/testsuite_performance.h	2003-12-16 22:58:38.000000000 +0100
+++ libstdc++-v3/testsuite/testsuite_performance.h	2003-12-17 10:06:48.000000000 +0100
@@ -185,13 +185,13 @@
 
     out.setf(std::ios_base::left);
     out << std::setw(25) << testname << tab;
-    out << std::setw(10) << comment << tab;
+    out << std::setw(25) << comment << tab;
 
     out.setf(std::ios_base::right);
     out << std::setw(4) << t.real_time() << "r" << space;
     out << std::setw(4) << t.user_time() << "u" << space;
     out << std::setw(4) << t.system_time() << "s" << space;
-    out << std::setw(4) << r.allocated_memory() << "mem" << space;
+    out << std::setw(8) << r.allocated_memory() << "mem" << space;
     out << std::setw(4) << r.hard_page_fault() << "pf" << space;
     
     out << std::endl;
@@ -211,7 +211,7 @@
 
     out.setf(std::ios_base::left);
     out << std::setw(25) << testname << tab;
-    out << std::setw(25) << header << tab;
+    out << std::setw(40) << header << tab;
 
     out << std::endl;
     out.close();

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]