title: How can I improve/replace sprintf, which I've measured to be a performance hotspot?
body: <p>Through profiling I've discovered that the sprintf here takes a long time.  Is there a better performing alternative that still handles the leading zeros in the y/m/d h/m/s fields?</p>
  
  <pre><code>SYSTEMTIME sysTime;
  GetLocalTime( &amp;sysTime );
  char buf[80];
  for (int i = 0; i &lt; 100000; i++)
  {
  
      sprintf(buf, "%4d-%02d-%02d %02d:%02d:%02d",
          sysTime.wYear, sysTime.wMonth, sysTime.wDay, 
          sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
  
  }
  </code></pre>
  
  <hr>
  
  <p>Note:  The OP explains in the comments that this is a stripped-down example.  The "real" loop contains additional code that uses varying time values from a database.  Profiling has pinpointed <code>sprintf()</code> as the offender.</p>