AA performance again
bearophile
bearophileHUGS at lycos.com
Mon Jun 9 13:49:52 PDT 2008
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
More information about the Digitalmars-d
mailing list