How would I optimize this parser?

bearophile bearophileHUGS at
Sun Oct 31 18:27:20 PDT 2010

If you import:
import core.memory: GC;

And then you disable the GC just before parsing:

The parsing runtime on my PC becomes about one third. Disabling the GC when you have to build a large data structure and re-enabling it after the creation is a normal optimization both in CPython and D.

You may also import:
import std.c.stdlib: exit;

And add this last line to the main:


to kill garbage collection at the end to remove the final collection time you weren't timing (but was there).

Now the total running time is about 0.3 seconds instead of 1.1 seconds.

All this means that your code is GC-bound :-) D GC is far worse than the Java one.

I will try to optimize other things.


More information about the Digitalmars-d-learn mailing list