Benchmarking counterstring implementations in TypeScript
Earlier this year I posted about how I implemented a counterstring function using “fake it till you make it”. I also posted about different ways to implement counterstrings. In this post, I want to share how those different implementations compare performance-wise.
To do this, I used both Tinybench and vitest bench (which uses Tinybench). The results are basically the same, but their default output is slightly different.
The nine implementations
Before I present the results, I should describe the different implementations and how they differ from each other. The actual code of each implementation is available on GitHub. Here I’ll only mention what makes each implementation interesting compared to the others: