AAs and GC
bearophile
bearophileHUGS at lycos.com
Mon Sep 10 02:26:57 PDT 2007
Hello, I think both D GC and AAs need more tuning, you can see it with the following two tiny tests too, that compare two quite similar programs that use AAs, Python (Py 2.5 + Psyco 1.5.2 on Win) agaist D (DMD v1.020). On my old PC the Python code is faster:
def main():
d = {}
for i in xrange(500000):
d["hello_" + str(i)] = i
import psyco; psyco.full()
main()
import std.string;
void main() {
int[string] d;
for(int i; i < 500_000; i++)
d["hello_" ~ toString(i)] = i;
}
Now I know how to write a D program faster than that Python+Psyco one, but the code becomes hairy (the GC can be disabled in Python too):
import std.c.stdio, std.gc;
void main() {
std.gc.disable();
uint[string] d;
char[15] key = "hello_";
for(uint i; i < 500_000; i++) {
auto nc = sprintf(key.ptr+6, "%d", i);
d[key[0 .. 6+nc].dup] = i;
}
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list