On Wed, 10 Nov 2010 11:33:45 -0500, Xie <xiema...@gmail.com> wrote:
Can't run a simple program. What's wrong, GC?
import std.stdio;
import std.date;
void f0()
{
wstring a[];
foreach(i; 0 .. 100_000_000)
{
a ~= " "w;
}
}
void main()
{
auto r = benchmark!(f0)(1);
writeln(r, "ms");
}
The results on my machine with 1G of memory is that it consumes 2G of
memory and the system starts thrashing. I changed the value to
10_000_000, and it runs in a couple seconds, I change it to 50_000_000 and
it runs in 200 seconds.
Something is definitely amiss here, because the following doesn't help (it
still consumes 1.2GB of memory):
void f0()
{
wstring a[];
a.reserve(100_000_000);
foreach(i; 0 .. 100_000_000)
{
a ~= " "w;
}
}
This should take the explosive nature of appending out of the equation,
because a reallocation should never occur.
I'll look into it.
-Steve