I called snprintfseveral times in a row with different arguments. I take the time needed for everyone snprintf. I found that the first call snprintftakes the longest time. After that, the time required to call the same function is reduced until it converges. What is the reason for this? I tried other functions and showed the same behavior.
I ask about this because it has to do with code performance testing. Usually in the main program this could be called only periodically. However, when I test the function separately, as in a loop, it will be faster, therefore, it will lead to inaccurate performance measurements.
The first call takes 4000 ++ ns, the second call takes 1700 ns, the third call takes 800 ns, until there are about 10 ++ calls, it is reduced to 130 ns.
snprintf(buffer, 32, "%d", randomGeneratedNumber1);
snprintf(buffer, 32, "%d", randomGeneratedNumber2);
.
.
.
source
share