Garbage collection in D

Robert Clipsham robert at octarineparrot.com
Wed Jun 3 02:36:25 PDT 2009


Diwaker Gupta wrote:
> I've just started to play around with D, and I'm hoping someone can clarify this. I wrote a very simple program that just allocates lots of objects, in order to benchmark the garbage collector in D. For comparison, I wrote the programs in C++, Java and D:
> C++: http://gist.github.com/122708
> Java: http://gist.github.com/122709
> D: http://gist.github.com/121790
> 
> With an iteration count of 99999999, I get the following numbers:
> JAVA:
> 0:01.60 elapsed, 1.25 user, 0.28 system
> C++:
> 0:04.99 elapsed, 4.97 user, 0.00 system
> D:
> 0:25.28 elapsed, 25.22 user, 0.00 system
> 
> As you can see, D is abysmally slow compared to C++ and Java. This is using the GNU gdc compiler. I'm hoping the community can give me some insight on what is going on.
> 
> Thanks,
> Diwaker

After porting the D version to tango:

D: 6.282s (ldmd -O5 -inline -release -L-s -singleobj gctest.d)
C++: 4.435s (g++ -O5 gctest.d)

This is on a C2D 2.2Ghz, 2GB RAM, Linux x86-64. I don't have java 
installed, so can't test that. Maybe if you're planning to use the GC a 
lot you should consider using tango?


More information about the Digitalmars-d-learn mailing list