Choosing Print Functions with a Lower Overhead
Some print functions have more overhead than others. “Overhead” refers to extra work that function must do compared to other functions. For example, printf has much more overhead than a function such as puts. Why is that?
The puts function is simple. It accepts a string of characters and writes them to the display. The printf
function, of course, will do the same thing, but it does a lot more. It examines the string of characters you, have sent to it, looking for special codes which indicate that internal data is to be printed. Perhaps your code doesn’t have internal characters, and you aren’t passing anything to it. Unfortunately, the function has no way of knowing that, and it must scan the string for special characters every time.
There is a smaller difference between the functions putch and puts, with putch being better (having less, overhead) if you plan to write only a single character. Unfortunately, the overhead incurred by these C functions is minuscule compared to the overhead of actually drawing the characters onto your display. Thus, this method will probably not gain the programmer very much, except in peculiar circumstances.
No comments:
Post a Comment