Am 01.12.2011, 14:29 Uhr, schrieb bearophile <bearophileh...@lycos.com>:

David Eagen:

I admit to being very new to D so perhaps I'm really doing something wrong.

This program uses string hashing, regular expressions, and by line file iteration. Those are among the most common operations done by script-like programs.

Some suggestions for your D code:
- Use the new regex engine
- Use File.byLine instead of BufferedFile
- don't use the built-in sort, use std.algorithm.sort
- try to minimize the number of memory allocations
- try to disable the GC if and when you think it's a good thing to do;
- avoid casts where possible.
- writef("%s,%d\n"  ==> writefln("%s,%d"

For Phobos devs: is the new regex engine able to support verbose regexes (it means that allow newlines, empty space and even comments)? In practice I only use them in Python.

Bye,
bearophile

Ok, so this is how you can optimize the program. In general we have to keep in mind that D is supposed to be convenient for scripting tasks and you don't usually optimize there, nor should in-depth knowledge of different sort algorithms, the GC or text I/O functions be required. This is something for an online-how-to-optimize :)

Btw,
write(relay, to!string(relayHosts[relay]), '\n');
is probably the "fastest" :p

Reply via email to