AA performance again
Steven Schveighoffer
schveiguy at yahoo.com
Mon Jun 9 14:01:53 PDT 2008
"bearophile" <bearophileHUGS at lycos.com> wrote in message
news:g2k51g$2j0j$1 at digitalmars.com...
> Walter Bright:
>>What is consuming the time is, as the memory usage grows, the garbage
>>collector repeatedly kicks in to look for things to free. You can see this
>>by wrapping the loop in:
> std.gc.disable();
> ... loop ...
> std.gc.enable();
> <
>
> The new timings disabling the GC are interesting:
> 1_000_000 0.26 s
> 2_000_000 0.57 s
> 5_000_000 2.11 s
> 10_000_000 8.79 s
> 20_000_000 29.78 s
>
>
> The modified D code I have used is:
>
> import std.conv: toUint;
> import std.gc: disable, enable;
> void main(string[] args) {
> uint n = toUint(args[1]);
> size_t[long] aa;
> disable;
> for (uint i; i < n; ++i)
> aa[i] = 0;
> enable;
> }
>
> ------------
>
> The original timings for D were:
> 100_000 0.05 s
> 500_000 0.20 s
> 1_000_000 0.47 s
> 2_000_000 1.25 s
> 5_000_000 5.93 s
> 10_000_000 24.34 s
> 20_000_000 129.8 s
>
> The original timings for Python (version 3, the most fair) were, best of
> 3:
> 10_000_000: 1.56 s
> 20_000_000: 3.04 s
>
> So even without GC, with N = 20 millions, Python is about 9.8 times
> faster, despite using boxed (64 bit, for this range) integers.
>
> Thank you for your answer,
> bearophile
for further reference, disabling the GC yields 6.5 seconds to do 10m inserts
on my system using dcollections' HashMap. I think it would be faster on
your system since your system's AAs do much better than mine.
Here is my code:
import dcollections.HashMap;
import tango.core.Memory;
void main()
{
const uint N = 10_000_000;
auto aa = new HashMap!(long, size_t);
tango.core.Memory.GC.disable();
for(uint i; i < N; ++i)
aa[i] = 0;
tango.core.Memory.GC.enable();
}
-Steve
More information about the Digitalmars-d
mailing list