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 libstdc++/18414] New: Performance problem in "operator new" and "operator new[]"


I wrote a test to measure the basic performance of "operator new[]". 
To my surprise, it came out to 3.1 usec per new/delete pair.
malloc(), on the other hand, came out to 980 microseconds.  

How could "operator new[]" be 3.5 times slower than "malloc"?
Well, it turns out that that time is almost entirely spent 
guaranteeing that malloc() doesn't wake up one morning and 
decide to throw some random exception.  Specifically, if I 
change the declaration of "operator new" (libstdc++-3.0/libsupc++/new_op.cc)
from:

  void *
  operator new (std::size_t sz) throw (std::bad_alloc)

to simply

  void *
  operator new (std::size_t sz) 

(and likewise for "operator new[]") then performance 
is much better --- operator new[] performs almost
indistinguishably from malloc().

I suggest fixing this by removing the "throw (std::bad_alloc)" from
the definition of "operator new" and "operator new[]".

I'm curious about any reaction you might have to this bug report.
Please feel free to contact me at kjd@duda.org.

Thanks,

Kenneth Duda

-- 
           Summary: Performance problem in "operator new" and "operator
                    new[]"
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kjd at duda dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin


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


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