title: How to speed up this code when converting float to string?
body: <p>I have profiled my unit test and the majority of the time the application is running is spent on this section of code. It is a function that converts a float to a string. How can I rewrite the code below to have a better speed performance? </p>
  
  <p>Am I misreading the report and the bottleneck is somewhere else?</p>
  
  <p>The profile reports states:</p>
  
  <blockquote>
    <p>Total CPU % = 13.02% , Self CPU % .07, Total CPU(ms) 769, Self CPU out
    of 100 percent 769 ms.</p>
  </blockquote>
  
  <p>769 out of 5907 samples.</p>
  
  <pre><code>std::string FloatToScientificString(float val, int width, int precision)
  {
      std::stringstream buffer;
      buffer &lt;&lt; std::scientific &lt;&lt; std::setw(width) &lt;&lt; std::setprecision(precision) &lt;&lt; std::setfill(' ') &lt;&lt; val;
      return buffer.str();
  }
  </code></pre>