So as a practical use of D I tried re-writing my Python program I use to process my referrer logs in D. My first pass was pretty sloppy and I end up touching every character in the file at least twice and in some cases three times. I thought I'd definitely be in need of a re-write, but the version I got working can rip through a 6MB file in 0.25 seconds, and that includes generating the HTML output.

I believe part of the speed comes from the use of 'invariant', which is like const in C and C++, but much stricter, that is, while const says a variable may not change, invariant says the underlying data will never change, and could, for example, be embedded in ROM. The other source of speed is probably D's use of non-null terminated strings. The other nice part of the code is that with bit of type inference that the D compiler does and useful expressions like 'foreach', the code was fairly easy to port from Python.

The code is here.

I wonder if someone has written an article about how much the use of inefficient languages contributes to the greenhouse effect and climate change. I bet you could get a very decent flamewar on with something like that.

Posted by Juri Pakaste on 2007-11-28

Um, there's a Delete button on the page that displays the code. I've got past the phase of pushing red buttons when I see them, but is that intentional?

Posted by James Abley on 2007-11-28

James,

No worries, both the creating and deleting of pastebin entries is protected by authentication.

Posted by Joe on 2007-11-28

So, how fast was the python version?

Posted by martin on 2007-11-28