Tiempo de ejecución prolongado para el programa c ++ en cygwin en comparación con linux

I have a c++ program which takes really long time to run in cygwin versus quick turnaround on a linux machine. I thought it could be a memory issue and tried to print the memory used and this is waht I see:

Linux

virtual memory: 5072 KB, Resident set size (RSS) : 1064 KB

Cygwin

virtual memory: 7672 KB, Resident set size (RSS) : 108928 KB

Can anyone help me understand what causes this difference? The cygwin is running on a laptop with 64-bit windows & and 3 GB memory. There is some old "C" code which does malloc in the program. Would converting these to standard c++ containers help?

preguntado el 09 de marzo de 12 a las 16:03

Without seeing the code, the options used to compile the program, and the versions of the toolchain programs, it is impossible to answer this question. -

are they the same hardware? If so: what James said plus OS call times. -

compilation is done using g++ -g <main.cpp> -o out.exe I'm using gcc version 4.5.3. I have the latest libs in cygwin installed. thanks -

@cppcoder you're comparing the performance of unoptimized code. I should shoot you. Use at least -O2 and rerun the comparison. -

Note that moving to standard containers won't make it faster but it will make your code better C++, -

2 Respuestas

Cygwin provides a POSIX compatibility layer on to of Windows. That is bound to be slower than code built against the native OS CRT.

If your code is Standard C or C++, recompile it with MSVC or MinGW/GCC and then compare it.

En otra nota, malloc vs new is a non-issue. Heap allocation is expensive.

What might be important is that Windows heap allocation is in general more expensive than Linux' implementation. The effect of this difference depends on your code.

respondido 09 mar '12, 16:03

Thanks for the suggestion..I'm using gcc 4.5.3 to compile. Will mingw be better? - codificador cpp

MinGW is GCC without Cygwin. It links to the same libraries MSVC links (almost), there's no cygwin dll involved, no compatibility code either. - rubenvb

As rubenvb says you can't really say without seeing the code - but:

The amount of memory is irrelevent, it may be that either the cygwin launcher or the OS decides to just allocate a lot of memeory to the cygwin job because that memory isn't being used. So future memory allocations by the cygwin app will be quicker. There is also an issue with how Linux reports memory use, it does optomistic allocation so if you allocate say a Gb of memory that memory isn't actualy locked to that process until it's used and the task won't show as using 1Gb.

There are some tasks which are very cheap on a Unix system but are very slow on Windows architecture. The most notorious is fork() which is very common on Unix apps but is a bad idea on Windows

respondido 09 mar '12, 16:03

Thanks for the suggestions. There are no forks..The program is pretty long with multiple files. I have not debugged where the run time issue is..So not sure which code to post. In cygwin, the program never completes :(. - codificador cpp

@user1200129 - no, that's why you need cygwin! Fork() on Window is CreateProcess, which is fork() then copy then exec() - which is slow - Martín Beckett

@cppcoder - cygwin access to the Windows file system can also be slow. There are some settings to speed it up if you don't need unix file modes (cygwin.com/cygwin-ug-net/using.html#mount-table) - Martín Beckett

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.