Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I like the OCaml version. It's both very easy to read and comes out really well in the benchmark.

I also looked at the "simple" Zig version, which came out really well in the benchmark, and to me it didn't look simple at all. It seems you need to make a lot of low level details explicit.

But IMHO AWK takes the crown here. :)



> But IMHO AWK takes the crown here. :)

Agreed! AWK is still the king of this stuff. For tasks like this, I kinda think AWK is nigh-unbeatable: so simple to write, so obvious what's going on (even if you've never seen any AWK program before, you're probably going to be able to figure out what's going on there), and decently performant.

AWK is the bee's knees.


On the other hand, I'm rather surprised that the Go version is almost as long and opaque as C.


Are you looking at the "simple" or the "optimized" versions? For the optimized, yes, the Go one is very similar to the C. For the simple, idiomatic version, the Go version [1] is much simpler than the C one [2]: 40 very straight-forward LoC vs 93 rather more complex ones including pointer arithmetic, tricky manual memory management, and so on.

[1] https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc... [2] https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc...


Yeah I meant the optimized versions.


TFA only talks about gawk, though, making this comparison meaningless ie. you can't benchmark languages but only language implementations. Same goes for other programming languages ofc unless those have only a single implementation.

mawk is an order of magnitude faster than gawk, and gawk isn't even the default on many Linuxen.


> TFA only talks about gawk, though, making this comparison meaningless

Not exactly! To quote from TFA (I'm the author):

> Another “optimization” is to run it using mawk, a faster AWK interpreter than gawk. In this case it’s about 1.7 times as fast as gawk -b. I’m using mawk in the benchmarks for the optimized version.


d'oh sorry didn't read that far




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: