Array Appending and DRuntime
dsimcha
dsimcha at yahoo.com
Sat Apr 25 16:05:02 PDT 2009
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> bearophile wrote:
> > Andrei Alexandrescu:
> >> I'm not sure on what machine you test, but on my (crappy old)
> >> laptop, your Appender example completes in 4.95 seconds. Are you
> >> sure you are measuring the right thing?
> >
> > My purpose is to have a good standard library and a good language.
> > Errors of mine are always possible. Benchmarks are tricky things.
> >
> > I have redone the tests, the CPU is unloaded, no computation is going
> > on, the system is WinXP with 2 GB RAM, 2 GHz Core 2.
> >
> > New timings give no less than 22.6 seconds, repeated. As running time
> > I use a timing command similar to the "time" of Linux, that gives the
> > total running time of the program (final deallocations too).
> >
> > I think Appender can be improved some.
> I can't improve what I can't measure. On my system, liberally loaded
> with a variety of programs, weaker than yours (1.8GHz/512MB laptop) I
> get 4.8s with -O and 5.3s without. The major difference is the OS
> (Ubuntu on my laptop), but I am puzzled as Appender doesn't assume a lot
> about the OS. I time with Unix time. I copied the code straight from
> your post. Please advise.
> Andrei
I think I can actually explain this. For some reason (I don't know why) the Linux
GC is less susceptible to false pointers than the Windows GC. You can prove this
by playing with associative arrays and seeing how big an associative array has to
get before there is a high probability that the GC won't free it. (See bugzilla
2105.)
I get timings more similar to Bearophile on my WinXP box. If blocks of memory
keep getting hit with false pointers on reallocation (which they do when arrays
get this big, at least on Windows), and you have to allocate more memory from the
OS, etc., of course it's going to be slower.
As for why the Linux GC is less susceptible to false pointers, I really don't
know. It's just an empirical observation. I would guess that maybe Linux
allocates from the top of the address space, where false pointers are less frequent.
Other than that, I would suggest only using 1,000,000 or so elements both because
100,000,000 is just plain unrealistic in most real-world use cases and because you
avoid false pointer issues that way.
More information about the Digitalmars-d
mailing list