Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Printf is horribly slow compared to puts


puts isn't applicable here because you actually need to format the %d, but any compiler worth using (i.e. not MSVC: https://gcc.godbolt.org/z/zx74vY1za) will optimize a printf of a constant string ending in a newline into a puts.


No you don't need to format the %d. The same way you collapsed the loop into the constant 5, you collapse that printf into puts("5\n")




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: