faster c++ version when compiled with optimizations