www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - AAs and GC

reply bearophile <bearophileHUGS lycos.com> writes:
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
Sep 10 2007
parent Manfred Nowak <svv1999 hotmail.com> writes:
bearophile wrote

 AAs need more tuning
... under which target function? Seems that D currently takes the lead at about 100 reads for a newly generated element. Below 100 reads, especially with zero reads, D seems indeed to be slower. -manfred
Sep 10 2007