4 ms·
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 rea
by yakubin 4y ago
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. :)
- OskarS 4y ago> 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.
- moffkalast 4y agoOn the other hand, I'm rather surprised that the Go version is almost as long and opaque as C.
- benhoyt 4y agoAre 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/c66dd01d868aa83dc30a9c95226575df1e5e1c5a/simple.go https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc... [2] https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc30a9c95226575df1e5e1c5a/simple.c https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc...
- moffkalast 4y agoYeah I meant the optimized versions.
- tannhaeuser 4y agoTFA 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.
- benhoyt 4y ago> 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.
- tannhaeuser 4y agod'oh sorry didn't read that far