The while implementation is approximately 5-10% faster (but I did not had much time to benchmark).

This implementation is about 35-40% faster. There might still be some possible improvements, this is the biggest bottleneck when we put IO-bound stuff aside.