One thought that strikes me after running gprof on the code is that you seem to maintain multiple deque's with the same data. E.g.
Code:
while ((_Price_List<Price_List[Auction_Color].end()) && (_Price_Response<Price_Response.end())){
if (*_Price_List<*_Price_Response) { // This is verz cricial
Price_Help[Auction_Color].push_back(*_Price_List);
Name_Help [Auction_Color].push_back(*_Name_List);
_Price_List++;
_Name_List++;
} else {
Price_Help[Auction_Color].push_back(*_Price_Response);
Name_Help [Auction_Color].push_back(friends[i]);
_Price_Response++;
}
}
while (_Price_List<Price_List[Auction_Color].end()) {
Price_Help[Auction_Color].push_back(*_Price_List);
Name_Help[Auction_Color].push_back(*_Name_List);
_Price_List++;
_Name_List++;
}
while (_Price_Response<Price_Response.end()) {
Price_Help[Auction_Color].push_back(*_Price_Response);
Name_Help[Auction_Color].push_back(friends[i]);
_Price_Response++;
}
I think it would create a bit less overhead if you had a struct/class containing the price and the name, and store that in a single deque. This will reduce the overhead of push_back() and iterator updates.
Here's the first five functions of gprof-output (running only 5 iterations):
Code:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
10.88 5.86 5.86 117668390 0.00 0.00 cAgent::_Production(int*, float&)
9.23 10.82 4.97 48064 0.00 0.00 cAgent::Ask_Prices()
5.96 14.04 3.21 58874421 0.00 0.00 cAgent::MPX(int, int*, int)
5.30 16.89 2.85 387271859 0.00 0.00 std::_Deque_iterator<float, float&, float*>::_Deque_iterator(std::_Deque_iterator<float, float&, float*> const&)
5.17 19.66 2.78 470673560 0.00 0.00 powf
Since _production is one of the top functions, and it calls pow() which is number 5 on the list, would it be possible to pre-calculate this calculaiton of pow():
Code:
void cAgent::_Production(int *Colors, float &y)
{
int i;
y=productivity;
for (i = 0; i < Number_of_Different_Colors; i++) {
y=y*pow(Colors[i],p[i]);
Colors[i]=1;
}
}
You may gain some speed in thise type of thing:
Code:
for (i = 0; i < Number_of_Different_Colors; i++){
lColors[i]=i_Colors[i];
iColors[i]=i_Colors[i];
}
by using memcpy:
Code:
memcpy(lColors, i_Colors, sizeof(lColors));
memcpy(iColors, i_Colors, sizeof(iColors));
Edit: I ran the last change, and MPX() went from being third on the list to about tenth place in time taken. There may be similar cases in other places - I only scanned the code briefly.
--
Mats