www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Memory RAM usage

reply bearophile <bearophileHUGS lycos.com> writes:
Today PCs have lot of RAM, so reducing the memory used by a program may seem
not so important, but practice shows that reducing the memory used by a program
reduces the cache traffic and increases cache coherence, so the code runs
faster (I have recently seen a 13X speedup in a not synthetic program just
modifying how memory is used and reducing memory usage, keeping the same
algorithm. I can show you an URL if you want). So reducing memory (and
improving cache usage patterns) is very important for D programs that want to
run fast.

Do you know how can Free Pascal use so little RAM? Here in this nbody benchmark
(a simple N body gravitational simulation) it seems to use less than half of
the memory used by C, yet the C code is tight and clean enough, and both use 64
bit floating point numbers:
http://shootout.alioth.debian.org/u32q/benchmark.php?test=nbody&lang=all&sort=kb
In other benchmarks memory usage of Free Pascal is not dramatically lower, but
it's usually near the top of lower memory usage in all Shootout benchmarks.

Bye,
bearophile
Dec 30 2009
parent reply grauzone <none example.net> writes:
bearophile wrote:
(I have recently seen a 13X speedup in a not synthetic program just modifying
how memory is used and reducing memory usage, keeping the same algorithm. I can
show you an URL if you want). 
Yes, please do!
 Do you know how can Free Pascal use so little RAM? Here in this nbody
benchmark (a simple N body gravitational simulation) it seems to use less than
half of the memory used by C, yet the C code is tight and clean enough, and
both use 64 bit floating point numbers:
 http://shootout.alioth.debian.org/u32q/benchmark.php?test=nbody&lang=all&sort=kb
 In other benchmarks memory usage of Free Pascal is not dramatically lower, but
it's usually near the top of lower memory usage in all Shootout benchmarks.
No idea. I just know that FPC doesn't use GCC. I think it doesn't even link to libc! (I can't really confirm, ldd crashes on the executable produced by fpc.) Maybe it just avoids some constant overhead due to this.
 Bye,
 bearophile
Dec 31 2009
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
grauzone:
 Yes, please do!
http://leonardo-m.livejournal.com/91798.html Bye, bearophile
Dec 31 2009
prev sibling parent BCS <none anon.com> writes:
Hello grauzone,

 bearophile wrote:
 
 In other benchmarks memory usage of Free Pascal is not dramatically
 lower, but it's usually near the top of lower memory usage in all
 Shootout benchmarks.
 
No idea. I just know that FPC doesn't use GCC. I think it doesn't even link to libc! (I can't really confirm, ldd crashes on the executable produced by fpc.) Maybe it just avoids some constant overhead due to this.
If that's the root, then it may well be a fictitious benefit because it may well have no effect on the resident set size (the amount of RAM actually used) during the main processing. All that it would be doing is to no include at all code that the C version never pulls off disk (executables lazy load on most systems).
Dec 31 2009