Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
91–100 of 234 posts
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#92Earlier quoted context omitted.
Ad uft8: it would change the problem only if the definition of word breaks changed. E.g., if a word break is defined by whitespace, then it probably doesn't.
What happens when the ASCII character for space is embedded within a multibyte UTF-8 codepoint?
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#93Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#94How about extending this to comparing programming language efficiency from a developer's standpoint, looking at bytes of code, versus the execution time? I took the source code file size from the repository, and the runtime from the blog post. Then I made an arbitrary overall "PAIN SCORE" (lower is better) by multiplying code size * runtime. I suggest this is a worthwhile metric simply because lower is better on both…
I did not check all files, but noticed that the simple rust code consists of about 60% comments (in terms of bytes), mostly due to a verbose blurb. It also spends about 15% of the non-comment bytes on printing nicer error messages, which is an interesting choice for a micro-benchmark. The simple C and FORTH versions similarly have a lot of comments.
Meanwhile a lot of the other files have very few or no comments.
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#95Doesn't the Unix Shell implementation break the "threading" constraint, in that each program in the pipe will have a main thread each, and all the programs will run concurrently? Or should the "threading" constraint really have been stated as "you can use multiple threads, but only if they all have their own address space"? Alternatively, given the multi-core capabilities of even budget/mobile/small systems these day…
I agree GPUs would probably do well on this problem, though it depends on how expensive the memory copying to/from the GPU ends up being. However, if you are going for all our performance, it seems like you could use SIMD like memchr or something.
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#96Not that it doesn't happen, it's just not something I've run into.
Just today I was testing out the performance difference hashing some Scylla queries and got nearly 2x faster hashing moving to fxhash.
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#97Earlier quoted context omitted.
> 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.
[1] https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc... [2] https://github.com/benhoyt/countwords/blob/c66dd01d868aa83dc...
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#98How about extending this to comparing programming language efficiency from a developer's standpoint, looking at bytes of code, versus the execution time? I took the source code file size from the repository, and the runtime from the blog post. Then I made an arbitrary overall "PAIN SCORE" (lower is better) by multiplying code size * runtime. I suggest this is a worthwhile metric simply because lower is better on both…
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#99Start with something not too far north of FizzBuzz but with a ton of scope to progressively enrich the problem until the clock runs out.
At $BIG_CO du jour people tend to talk about how much “signal” an interview produces, and starting somewhere that a meaningful number of candidates can’t do anything with offers very little “signal”, likewise very little Shannon information.
Great article!
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#100I 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. :)
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.
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.