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

Re: The strange speed of a program!


> I have a program whose speed is so strange to me. It is maily used

Same here (compiled with -O2):

./a.out 50 1024 0   ->   CPU time: 6.510000 sec
./a.out 50 1024 1   ->   CPU time: 3.880000 sec

but with different arguments:

./a.out 1000 128 0  ->   CPU time: 0.270000 sec
./a.out 1000 128 1  ->   CPU time: 2.960000 sec

This is also very interesting: If you copy the initializing
for-loop once *before* starting the timer, you can't reproduce
the odd effect anymore.

./a.out 50 1024 0   ->   CPU time: 2.210000 sec
./a.out 50 1024 1   ->   CPU time: 4.040000 sec

and

./a.out 1000 128 0  ->   CPU time: 0.710000 sec
./a.out 1000 128 1  ->   CPU time: 2.990000 sec

Someone more knowledgable than me will explain it using the
right terms.  I can only say that it has something to do with
how the kernel (linux here) manages memory.  I once found out
that memory physically gets allocated only at its first use,
not during the malloc(), i.e. very large chunks can be allocated
without causing any swapping.  The swapping only starts to take
place when you use that memory for the first time.  Maybe in
above case the kernel 'knows' that the memory pages are being
read without ever having been initialized and doesn't bother
loading anything... just speculation.

jlh


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