For my project I switched from GCC 5 to GCC 9 and found that the performance got worse. I did some investigations and came up with a simple source code which reproduces the behaviour.
I compile the code using different GCC versions (g++-5 and g++-9) on the same machine
#include <queue>
int main()
{
std::priority_queue<int> q;
for (int j = 0; j < 2000; j ++) {
for (int i = 0; i < 20000; i ++) {
q.emplace(i);
}
for (int i = 0; i < 20000; i ++) {
q.pop();
}
}
return 0;
}
When I compile it using GCC 5 I get the following timings:
# g++-5 -std=c++14 -O3 main.cpp
# time ./a.out
real 0m1.580s
user 0m1.578s
sys 0m0.001s
Doing the same with GCC 9 I get:
# g++-9 -std=c++14 -O3 main.cpp
# time ./a.out
real 0m2.292s
user 0m2.288s
sys 0m0.003s
As you can see GCC 9 gives slower results.
I am not sure that the issue is in the STL priority_queue itself. I tried the boost priority_queue and got the same results.
Does anyone have a clue why the performance of this app is slower for GCC 9 comparing to GCC 5? Maybe I should use some compiler flags? Thank you in advance!
g++ --version
). – Confluentstd::__adjust_heap
whereas GCC-5 does not inlinestd::vector::_M_emplace_back_aux
. Why they chose to do that with a single call-site in both cases is beyond me but I guess it could just be a tweak in the tuning options – Castled