AIX xlC implementation of STL significantly slower than other platforms?
-
23-08-2019 - |
Question
Something that takes 1 second to run on Linux takes 45 seconds to run on AIX. I haven't dug directly into that code but as a test grabbed a small application that does very little from another SO question:
int main ( int argc, char **argv)
{
int i = 0;
std::vector<int> vec;
vec.push_back(6);
vec.push_back(-17);
vec.push_back(12);
for (i=0;i<100000;i++)
vec.push_back(i);
vec.erase(vec.begin() + 1);
return 0;
}
I have an old compiler (7.0.0.10) and I cannot belive how much slower the code runs vs. the same code on g++ 4.2.
Has anyone seen this before? It would take some work to upgrade the compiler. The sample code is about 20 times slower (real time) on a system with almost no load.
Update Reqested Box Specifications:
Number Of Processors: 8 Processor Clock Speed: 3504 MHz CPU Type: 64-bit Kernel Type: 64-bit Memory Size: 63232 MB Good Memory Size: 63232 MB Platform Firmware level: EM340_041 Firmware Version: IBM,EM340_041 Console Login: enable Auto Restart: true Full Core: true
Output on AIX:
real 0m0.52s
user 0m0.51s
sys 0m0.00s
Output on Linux:
0.00s real 0.01s user 0.00s system
Solution
I suspect a suboptimal memory allocation strategy. What happens if you add
vec.reserve(10000);
before the for-loop?
OTHER TIPS
Either there is something seriously wrong with your setup, or you haven't posted the real code. The folowing executes almost instantly on a very old 900Mhz Pentium laptop with little memory:
#include <iostream>
#include <vector>
#include <ctime>
using namespace std;;
int main ( int argc, char **argv) {
time_t now1 = time(0);
std::vector<int> vec;
vec.push_back(6);
vec.push_back(-17);
vec.push_back(12);
for ( int i = 0; i<10000; i++) {
vec.push_back(i);
}
time_t now2 = time(0);
vec.erase(vec.begin() + 1);
time_t now3 = time(0);
cout << (now2 - now1) << " " << (now3 - now2) << endl;
}
Please run this code through both compilers and report the numbers it outputs.
A couple of suggestions to narrow down the problem:
- Use time on your program and look at the system/user times, not elapsed time. That will give you a better indication.
- put a
system("date")
before each of the three initial push_back statements, before the for loop, before the erase and before the return. This will show which operation is causing the problem. - Tell us what hardware you're running on as well. You may have a 286-class pSeries.
Then get back to us with the hard data and we can help out some more.