My original benchmark read the file as a stream — no guarantee that you'll get whole characters in each read — so I modified it a bit to read the whole file into memory, parse it, and print out the number of characters decoded and an XOR "hash". Here's what happened (looking at the "user" line of `time` output):
- Bjoern Hoehrmann’s decoder: 2.159s
- This post’s decoder: 2.754s (27.6% slower)
- Naive decoder: 1.453s (32.7% faster)
I'm curious whether this test makes sense and, if so, why there's such a big difference. Currently my best guess is the data cache pressure mentioned in twoodfin's comment.
I guess I should write a blog post, too.
Naive parser: https://gist.github.com/s4y/7c95f1ebeb2c069cfb09db3c3251eca3
Benchmarks: https://gist.github.com/s4y/344a355f8c1f99c6a4cb2347ec4323cc