How about caching the results? Isn't that a possibility? Considering that this particular sprintf() call is made too often in your code, I'm assuming that between most of these consecutive calls, the year, month and day do not change.
Thus, we can implement something like the following. Declare an old and a current SYSTEMTIME structure:
SYSTEMTIME sysTime, oldSysTime;
Also, declare separate parts to hold the date and the time:
char datePart[80];
char timePart[80];
For, the first time, you'll have to fill in both sysTime, oldSysTime as well as datePart and timePart. But subsequent sprintf()'s can be made quite faster as given below:
sprintf (timePart, "%02d:%02d:%02d", sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
if (oldSysTime.wYear == sysTime.wYear &&
oldSysTime.wMonth == sysTime.wMonth &&
oldSysTime.wDay == sysTime.wDay)
{
// we can reuse the date part
strcpy (buff, datePart);
strcat (buff, timePart);
}
else {
// we need to regenerate the date part as well
sprintf (datePart, "%4d-%02d-%02d", sysTime.wYear, sysTime.wMonth, sysTime.wDay);
strcpy (buff, datePart);
strcat (buff, timePart);
}
memcpy (&oldSysTime, &sysTime, sizeof (SYSTEMTIME));
Above code has some redundancy to make the code easier to understand. You can factor out easily. You can further speed up if you know that even hour and minutes won't change faster than your call to the routine.