This is the mail archive of the gcc-bugs@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]

[Bug c++/14563] octave built under Cygwin very slow


------- Additional Comments From paulthomas2 at wanadoo dot fr  2004-04-03 17:54 -------
Subject: Re:  octave built under Cygwin very slow

Hi,

It's good to know that you are enagaging with this one.  I sent a 
message this morning that some how got deleted in the process of being 
sent; it's main content was not to forget that the most extreme 
manifestation of the difference is with g++ 3.3.1 (cygming special) for 
which

new/delete takes 1900ns/loop
malloc/erase          400ns/loop  

This is how we detected this in the first place.

For reference, on the same Athlon 1700, 3.2.2 20030222 (RH 3.2.2-5)

Gives

new/delete              140ns/loop
malloc/erase            100ns/loop

Unfortunately, I just this morning deleted the g++ 3.3.1 and replaced it 
with 3.2 (which does not show such aberrant behaviour, by the way) , so 
I cannot test your patch!

Paul Thomas


epanelelytha at kellertimo dot de wrote:

>------- Additional Comments From epanelelytha at kellertimo dot de  2004-04-03 17:18 -------
>I inlined all allocation operators and they inproved from 2.393s to 1.922s (C
>allocation style: 2.013s). Note that I also changed the test program to allocate
>an array of 100 unsigned ints.
>The problem with inlining them is that this can only work if <new> is included,
>so please don't understand this as a patch, but as an idea/explanation why new
>is slower than malloc.
>
>Reading specs from /usr/local/lib/gcc/i686-pc-cygwin/3.5-tree-ssa/specs
>Configured with: ./configure --disable-libmudflap --without-libbanshee
>--disable-checking --enable-languages=c,c++ --disable-threads : (reconfigured) 
>: (reconfigured) ./configure --disable-libmudflap
> --without-libbanshee --disable-checking --enable-languages=c,c++
>--disable-threads : (reconfigured)
>  : (reconfigured) ./configure --disable-libmudflap --without-libbanshee
>--disable-checking --enable-languages=c,c++ --disable-threads : (reconfigured) 
>: (reconfigured) ./configure --disable-libmudflap --without-libbanshee
>--disable-checking --enable-languages=c,c++ --disable-threads
>Thread model: single
>gcc version 3.5-tree-ssa 20040403 (merged 20040331)
>
>#include <iostream>
>#include <stdio.h>
>#include <time.h>
>using namespace std;
>
>int main()
>{
>	const size_t array_size = 100;
>	const unsigned loop_count = 1000000;
>	long t1 = clock();
>	for (unsigned iloop = 0; iloop < loop_count; iloop++)
>	{
>		unsigned *myarray = new unsigned [array_size];
>		delete [] myarray;
>	}
>	long t2 = clock();
>	double delt1 = (double)( t2 - t1 )/ (double)(CLOCKS_PER_SEC);
>	cout << "done looping time 1=" << delt1 << endl;
>	long t3 = clock();
>
>	for (unsigned iloop = 0; iloop < loop_count; iloop++)
>	{
>		unsigned *myarray = (unsigned *)malloc(array_size * sizeof(unsigned));
>		if (myarray== NULL) { printf("alloc failed\n"); exit(1); }
>		else free (myarray);
>	}
>	long t4 = clock();
>	double delt2 = (double)( t4 - t3 )/ (double)(CLOCKS_PER_SEC);
>	cout << "done looping time 2=" << delt2 << endl;
>
>	return 0;
>}
>
>
>
>Index: gcc/libstdc++-v3/libsupc++/del_op.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/del_op.cc,v
>retrieving revision 1.2.22.1
>diff -u -r1.2.22.1 del_op.cc
>--- gcc/libstdc++-v3/libsupc++/del_op.cc	3 Jun 2003 16:53:00 -0000	1.2.22.1
>+++ gcc/libstdc++-v3/libsupc++/del_op.cc	3 Apr 2004 17:11:53 -0000
>@@ -30,11 +30,3 @@
> 
> #include "new"
> 
>-extern "C" void free (void *);
>-
>-void
>-operator delete (void *ptr) throw ()
>-{
>-  if (ptr)
>-    free (ptr);
>-}
>Index: gcc/libstdc++-v3/libsupc++/del_opnt.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/del_opnt.cc,v
>retrieving revision 1.2.22.1
>diff -u -r1.2.22.1 del_opnt.cc
>--- gcc/libstdc++-v3/libsupc++/del_opnt.cc	3 Jun 2003 16:53:00 -0000	1.2.22.1
>+++ gcc/libstdc++-v3/libsupc++/del_opnt.cc	3 Apr 2004 17:11:53 -0000
>@@ -30,11 +30,3 @@
> 
> #include "new"
> 
>-extern "C" void free (void *);
>-
>-void
>-operator delete (void *ptr, const std::nothrow_t&) throw ()
>-{
>-  if (ptr)
>-    free (ptr);
>-}
>Index: gcc/libstdc++-v3/libsupc++/del_opv.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/del_opv.cc,v
>retrieving revision 1.2.22.1
>diff -u -r1.2.22.1 del_opv.cc
>--- gcc/libstdc++-v3/libsupc++/del_opv.cc	3 Jun 2003 16:53:00 -0000	1.2.22.1
>+++ gcc/libstdc++-v3/libsupc++/del_opv.cc	3 Apr 2004 17:11:53 -0000
>@@ -29,9 +29,3 @@
> // the GNU General Public License.
> 
> #include "new"
>-
>-void
>-operator delete[] (void *ptr) throw ()
>-{
>-  ::operator delete (ptr);
>-}
>Index: gcc/libstdc++-v3/libsupc++/del_opvnt.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/del_opvnt.cc,v
>retrieving revision 1.2.22.1
>diff -u -r1.2.22.1 del_opvnt.cc
>--- gcc/libstdc++-v3/libsupc++/del_opvnt.cc	3 Jun 2003 16:53:00 -0000	1.2.22.1
>+++ gcc/libstdc++-v3/libsupc++/del_opvnt.cc	3 Apr 2004 17:11:53 -0000
>@@ -29,9 +29,3 @@
> // the GNU General Public License.
> 
> #include "new"
>-
>-void
>-operator delete[] (void *ptr, const std::nothrow_t&) throw ()
>-{
>-  ::operator delete (ptr);
>-}
>Index: gcc/libstdc++-v3/libsupc++/new
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/new,v
>retrieving revision 1.10.2.5
>diff -u -r1.10.2.5 new
>--- gcc/libstdc++-v3/libsupc++/new	21 Jul 2003 13:54:08 -0000	1.10.2.5
>+++ gcc/libstdc++-v3/libsupc++/new	3 Apr 2004 17:11:53 -0000
>@@ -39,6 +39,7 @@
> #define _NEW
> 
> #include <cstddef>
>+#include <cstdlib>
> #include <exception>
> 
> extern "C++" {
>@@ -68,6 +69,10 @@
>   new_handler set_new_handler(new_handler) throw();
> } // namespace std
> 
>+
>+void* __operator_new(std::size_t) throw (std::bad_alloc);
>+void* __operator_new_nothrow(std::size_t) throw ();
>+
> //@{
> /** These are replaceable signatures:
>  *  - normal single new and delete (no arguments, throw @c bad_alloc on error)
>@@ -79,14 +84,55 @@
>  *  Placement new and delete signatures (take a memory address argument,
>  *  does nothing) may not be replaced by a user's program.
> */
>-void* operator new(std::size_t) throw (std::bad_alloc);
>-void* operator new[](std::size_t) throw (std::bad_alloc);
>-void operator delete(void*) throw();
>-void operator delete[](void*) throw();
>-void* operator new(std::size_t, const std::nothrow_t&) throw();
>-void* operator new[](std::size_t, const std::nothrow_t&) throw();
>-void operator delete(void*, const std::nothrow_t&) throw();
>-void operator delete[](void*, const std::nothrow_t&) throw();
>+inline void* operator new(std::size_t sz) throw (std::bad_alloc)
>+{
>+  /* malloc (0) is unpredictable; avoid it.  */
>+  if (sz == 0)
>+    sz = 1;
>+  void *p = std::malloc (sz);
>+  if (!p)
>+    p = __operator_new(sz);
>+
>+  return p;
>+}
>+inline void* operator new[] (std::size_t sz) throw (std::bad_alloc)
>+{
>+  return ::operator new(sz);
>+}
>+inline void operator delete (void *ptr) throw ()
>+{
>+  if (ptr)
>+    std::free (ptr);
>+}
>+inline void operator delete[] (void *ptr) throw ()
>+{
>+  ::operator delete (ptr);
>+}
>+
>+inline void* operator new (std::size_t sz, const std::nothrow_t&) throw()
>+{
>+  /* malloc (0) is unpredictable; avoid it.  */
>+  if (sz == 0)
>+    sz = 1;
>+  void *p = std::malloc (sz);
>+  if (!p)
>+    p = __operator_new_nothrow(sz);
>+
>+  return p;
>+}
>+inline void* operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
>+{
>+  return ::operator new(sz, nothrow);
>+}
>+inline void operator delete (void *ptr, const std::nothrow_t&) throw ()
>+{
>+  if (ptr)
>+    std::free (ptr);
>+}
>+inline void operator delete[] (void *ptr, const std::nothrow_t&) throw ()
>+{
>+  ::operator delete (ptr);
>+}
> 
> // Default placement versions of operator new.
> inline void* operator new(std::size_t, void* __p) throw() { return __p; }
>Index: gcc/libstdc++-v3/libsupc++/new_op.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/new_op.cc,v
>retrieving revision 1.5.2.1
>diff -u -r1.5.2.1 new_op.cc
>--- gcc/libstdc++-v3/libsupc++/new_op.cc	3 Jun 2003 16:53:00 -0000	1.5.2.1
>+++ gcc/libstdc++-v3/libsupc++/new_op.cc	3 Apr 2004 17:11:53 -0000
>@@ -37,27 +37,22 @@
> 
> extern new_handler __new_handler;
> 
>-void *
>-operator new (std::size_t sz) throw (std::bad_alloc)
>+void* __operator_new(std::size_t sz) throw (std::bad_alloc)
> {
>   void *p;
>-
>-  /* malloc (0) is unpredictable; avoid it.  */
>-  if (sz == 0)
>-    sz = 1;
>-  p = (void *) malloc (sz);
>-  while (p == 0)
>+  do
>     {
>-      new_handler handler = __new_handler;
>+      std::new_handler handler = __new_handler;
>       if (! handler)
> #ifdef __EXCEPTIONS
>-	throw bad_alloc();
>+        throw std::bad_alloc();
> #else
>         std::abort();
> #endif
>       handler ();
>-      p = (void *) malloc (sz);
>+      p = std::malloc (sz);
>     }
>+  while (!p);
> 
>   return p;
> }
>Index: gcc/libstdc++-v3/libsupc++/new_opnt.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/new_opnt.cc,v
>retrieving revision 1.3.22.1
>diff -u -r1.3.22.1 new_opnt.cc
>--- gcc/libstdc++-v3/libsupc++/new_opnt.cc	3 Jun 2003 16:53:00 -0000	1.3.22.1
>+++ gcc/libstdc++-v3/libsupc++/new_opnt.cc	3 Apr 2004 17:11:53 -0000
>@@ -36,31 +36,26 @@
> extern "C" void *malloc (std::size_t);
> extern new_handler __new_handler;
> 
>-void *
>-operator new (std::size_t sz, const std::nothrow_t&) throw()
>+void* __operator_new_nothrow(std::size_t sz) throw ()
> {
>   void *p;
>-
>-  /* malloc (0) is unpredictable; avoid it.  */
>-  if (sz == 0)
>-    sz = 1;
>-  p = (void *) malloc (sz);
>-  while (p == 0)
>+  do
>     {
>-      new_handler handler = __new_handler;
>+      std::new_handler handler = __new_handler;
>       if (! handler)
>-	return 0;
>+	    return 0;
>       try
>-	{
>-	  handler ();
>-	}
>-      catch (bad_alloc &)
>-	{
>-	  return 0;
>-	}
>+	    {
>+	      handler ();
>+	    }
>+      catch (std::bad_alloc &)
>+	    {
>+	      return 0;
>+	    }
> 
>-      p = (void *) malloc (sz);
>+      p = std::malloc (sz);
>     }
>+  while (!p);
> 
>   return p;
> }
>Index: gcc/libstdc++-v3/libsupc++/new_opv.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/new_opv.cc,v
>retrieving revision 1.3.22.1
>diff -u -r1.3.22.1 new_opv.cc
>--- gcc/libstdc++-v3/libsupc++/new_opv.cc	3 Jun 2003 16:53:00 -0000	1.3.22.1
>+++ gcc/libstdc++-v3/libsupc++/new_opv.cc	3 Apr 2004 17:11:53 -0000
>@@ -30,8 +30,3 @@
> 
> #include "new"
> 
>-void *
>-operator new[] (std::size_t sz) throw (std::bad_alloc)
>-{
>-  return ::operator new(sz);
>-}
>Index: gcc/libstdc++-v3/libsupc++/new_opvnt.cc
>===================================================================
>RCS file: /cvsroot/gcc/gcc/libstdc++-v3/libsupc++/new_opvnt.cc,v
>retrieving revision 1.3.22.1
>diff -u -r1.3.22.1 new_opvnt.cc
>--- gcc/libstdc++-v3/libsupc++/new_opvnt.cc	3 Jun 2003 16:53:00 -0000	1.3.22.1
>+++ gcc/libstdc++-v3/libsupc++/new_opvnt.cc	3 Apr 2004 17:11:53 -0000
>@@ -30,8 +30,3 @@
> 
> #include "new"
> 
>-void *
>-operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
>-{
>-  return ::operator new(sz, nothrow);
>-}
>
>  
>




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14563


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