<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56202>56202</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++] int-to-string conversions significantly slower on mingw
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alvinhochun
      </td>
    </tr>
</table>

<pre>
    This is the same issue as https://github.com/llvm/llvm-project/issues/40476 but specifically for mingw. The prior issue was fixed for MSVC with https://reviews.llvm.org/D59525 and the follow-up https://reviews.llvm.org/D59727, but mingw still uses the slow path requiring `__libcpp_locale_guard`.

I don't have proper benchmark data now, but converting numbers to strings using `std::ostringstream` is apparently quite slow on mingw. Especially when the current locale is not `"C"`, the `setlocale` call takes the majority of time (see image below). When the locale is already `"C"` it seems about a magnitude faster but `setlocale` is still quite significant in profiling data.

![profiling](https://user-images.githubusercontent.com/2397650/175570963-78f8d6aa-28d9-40a0-80a3-343992ad2a1e.png)

([This](https://github.com/AcademySoftwareFoundation/OpenColorIO/blob/a2e204b378223a065f8816f5950cf96ed0e99ef0/src/OpenColorIO/Processor.cpp#L549) is the code in use.)

The toolchain we use is llvm-mingw 20220323 (LLVM 14.0.0).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVE2P2zYQ_TXyhZBAU98HHzZ2FwiwQQokSI-LETmymFCiSlJW9993KNtJnfRQ1JD1QQ753puZx86qt8PnQXtGVxiQeRiR3v2CDDwbQph9kj8l4pmusw7D0mXSjvRhzOX-SGdnv6IM9Lmt9PRS8KKuWLcE5meUutcSjHljvXVs1NN5zdhnQpudpoEr3Ep4vf4L1Rb04dOXI1sJ8CcODi8aV59F3My6Mw2dyrYUJYNJbQp6a4xd02X-TytrUSfiuBHdeDEftDFs8XjLB-3FZiAeDv9ctKMYllT89dXoTs7zq7EkDF_PC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