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bIaDh5GrXzw343Cj1VOI2EwDCpoKu_OX_58m9YoRxx2bqiDwr_iJ0cydmg2ki9H5v8DdcXu7Q>53267</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
std::deque/std::stack construction is more expensive than GCC
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
I came across this while working on https://github.com/danmar/cppcheck/pull/3716.
Using `std::stack` in Clang with the default `std::deque` backend is more expensive than doing so in GCC. It's about 10% slower. In the case I came across this I was able to speed this up using `std::vector` instead. That actually helped both compilers but Clang profited more from that.
The problem is the `std::_Deque_base<void*, std::allocator<void*> >::_M_initialize_map(unsigned long)` which GCC does not generate in the code - see https://godbolt.org/z/v1d9GsGnW.
Here's some sample code I used for profiling with `-O2` and `callgrind`:
```cpp
#include <stack>
extern void f()
{
std::stack<void*> stk;
stk.push(nullptr);
}
int main()
{
for (int i = 0; i < 100000; ++i)
{
f();
}
return 0;
}
```
Total Ir:
Clang `43,790,737`
GCC `39,794,842`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VE2T2ygQ_TXypWtcMrIt-6DDjJ2Z9WErl2ztcQqJtsUOBgWQneTX5yF_ZOzJRiUhoLsfrx8NtVPfqw01cs8kG-9CoNjqQMdWG6aj82_a7shZamPsQlY8ZuIZ707Htq_HjdtjoKTdS49O03VNy80bul1vDH5FOZmPs3yd5Y-n9p-Q8LJ5HqJKaMVjiBIR85y0pZWRsB4BDhZMireyN_HGXfHXnpN7jTC2ikB27zwTf-vYBn1ghEpLyqWFgkuwL6vVmDYxE2UgWbs-0iTPxIyCcUf2MNlhuUYGpt9osaGjTIEQJDoKHbM6GfqO-g_5HLiJzp8SCpGlGtOXVkYgxl4a851aNh0QaocsIWAHoX2gGqxO6XfebXWEx5DW1rt9yijeyPgFdOEHSvskQGL_nsPrOqn0WiOhrF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