This is the mail archive of the cygwin mailing list for the Cygwin 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]

new vs malloc, -fno-exception - Re: Serious performance problems (malloc related?)


here's a little study, allocating / freeing mem in a loop, once with the
C malloc/free, once (-DUSE_CXX_HEAP) using new/delete. It reproduces the
factor ~3 for gcc cygwin.

I've built it with MSVC's cl 7.0, gcc 3.3.3, with and without
-mno-cygwin, using the cygwin-inst snapshot from 20050528, cygwin update
from today, on a P4 1.8GHz, 512MB RAM, XPSP2 Prof.

Result: the user fraction with "new" is 3 times the user fraction with
"malloc". mingw and MSVC show no measurable difference.[1][2]

cl -nologo :
real    0m3.094s
user    0m0.030s
sys     0m0.016s
g++ -mno-cygwin :
real    0m3.733s
user    0m0.031s
sys     0m0.000s
g++ :
real    0m4.226s
user    0m2.358s
sys     0m1.796s
cl -nologo -DUSE_CXX_HEAP:
real    0m3.114s
user    0m0.015s
sys     0m0.015s
g++ -mno-cygwin -DUSE_CXX_HEAP:
real    0m3.811s
user    0m0.015s
sys     0m0.015s
real    0m8.779s
user    0m7.030s
sys     0m1.671s

To reproduce run make.

NOTE: -fno-exceptions has no measurable impact on the results.

Hope that helps, otherwise just ignore it (well - there no need to say
that on cygwin-ml, I suppose :-)


NB: the reason I care is because we see the same performance hit (since
a few months) in the cygwin port of the _open_source_ program ROOT

[1]: The binary is run twice to make sure that the win cache is in the
same state for all combinations. (Disabling the cache might be of
academical interest. It's not real-world, real-use compatible, though.)

[2]: The sys fraction is considerably higher (O(100)) for gcc compared
with mingw/cl. I realize this is somewhat expected - but the amount is
astonishing to me nevertheless. Anyway - that's for later.
#include <new>
#define malloc(SIZE) new char[SIZE] 
#define free(POS) delete[] POS
#include <stdlib.h>

int main(int argc, char* argv[]) {
   const size_t size=1000;
   const long int loop0=10;
   const long int loop1=100000;
   char *ptr[loop1];
   int i0=0;
   int i1=0;

   for(;i0<loop0;++i0) {
   return 0;
	rm -f $(OUTFILE)
	$(MAKE) builds
	cat $(OUTFILE)
	CXX="cl -nologo" $(MAKE) run
	CXX="g++ -mno-cygwin" $(MAKE) run
	CXX=g++ $(MAKE) run
	@$(CXX) $(USE_CXX_HEAP) check_cyg_mem.cxx -o check_cyg_mem.exe \
	&& ./check_cyg_mem.exe \
	&& echo -n "$(CXX) $(USE_CXX_HEAP): " >> $(OUTFILE) \
	&& bash -c "time ./check_cyg_mem.exe" >> $(OUTFILE) 2>&1

.phony: all builds run

Unsubscribe info:
Problem reports:

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