C: massive speed improvements