I wrote an AR archive (.a files) parser in D

Renato renato at athaydes.com
Sat Aug 17 19:05:22 UTC 2024


On Sunday, 4 August 2024 at 20:14:50 UTC, Renato wrote:
> Just announcing here in case someone may be interested in that 
> (the code is very easy to read) and wants to give some feedback 
> on my usage of D (I'm not experienced in D, just using it for 
> some fun every now and then).

I wrote this also in Dart and Common Lisp as I was curious how D 
would compare to them.

Dart can parse libphobos.a in 1.3 seconds, and Common Lisp in 
around 1.5.
With D, it took only 0.4 seconds! And the code is actually the 
easiest to read IMHO.

A win for D :)

Both Dart and Common Lisp are pretty fast (for my usual needs, 
Lisp in particular is very, very fast for small scripts like 
this, sometimes beating Rust in my previous comparisons), so the 
bar was not too low as I see it. I am afraid the speedup may be 
due to D using mmap, and the other languages just reading the 
file in chunks. But my goal was not to make a fair benchmark!! It 
was to write the code for this in the most "natural" way that the 
language allowed... I used mmap in D because it's in the stdlib! 
In the other languages, it's possible only via libs. I might 
later convert D to use the exact same approach as in the other 
languages, just for curiosity... and I think that should be 
pretty easy, and if it is, it will prove to me that D really is a 
flexible language that makes it "easy" to modify code... will see.

I know I should also write it in Rust to feel more "convinced" to 
use D... but I am not sure I will bother because I already know 
Rust and I just don't feel like using it for anything (it's a 
combination of hard to write and modify code, ridiculous slow 
compile times even for small projects, but specially when using 
libs, which you need to for even the most basic stuff like proper 
error reporting etc....).

Anyway, in the unlikely case someone is curious about what code 
looks like in these 3 languages:

D: https://github.com/renatoathaydes/dar/blob/main/source/dar.d

Dart and Common Lisp: 
https://gist.github.com/renatoathaydes/54a93e91cacfafd08ad875f11615fbc2


More information about the Digitalmars-d mailing list