C++ How to speed up my prog design
<p>i am trying to design a chord system..</p>

<p>the problem is my system works fine if the size is like 10-20 lines of addPeer, removePeer etc..</p>

<p>but when i test it with a like 5000 lines of command file.</p>

<p>the first few hundreds was pretty fast, but as the program load more and more lines, it start to get slow..</p>

<p>As the requirement of the program is to test my program design, i cannot use threading.</p>

<p>I heard pointer is a good way to get things done faster, but how do i use pointer for my case.</p>

<p>This is my class headers..</p>

<pre><code>class chord 
{
public:
chord();
~chord();

struct fingerTable {
int index;
int key;
};

struct node {
int nodeid;
vector&lt;fingerTable&gt; fTable;
vector&lt;string&gt; data;
};

void addPeer(int);

vector&lt;node&gt; cNode;
vector&lt;fingerTable&gt; fTable;

/* SOME more functions ..*/
};
</code></pre>

<p>This is my addPeer Function</p>

<pre><code>void chord::addPeer(int id)
{
//id = node ID
int fIndex,nextNode;
node newNode;
vector&lt;fingerTable&gt; ft1;
vector&lt;string&gt; data1;
//increment indexCounter
//indexCounter++;

newNode.nodeid = id;
//insert a blank fingerTable first.
newNode.fTable = ft1;
//insert a blank data first.
newNode.data = data1;

//push back node to vector chord Index Node
cNode.push_back(newNode);
//indexCounter++;
//perform finger table computation

//sort it base on its NodeID
sort(cNode.begin(),cNode.end(),sortByNodeID);

for(int i=0;i&lt;cNode.size();i++)
{
if(cNode[i].nodeid==id)
{
fIndex=i;
}
}//end for loop to loop finding index of node

if(fIndex!=cNode.size()-1)
{
//if not last element
nextNode=fIndex+1;
}
else
{
nextNode=0;
}

//now we get the message vector of the next node and do a datashift on it.
data1 = cNode[nextNode].data;
//clear its data away so we can empty it and re-arrange it.
cNode[nextNode].data.clear();
//performing data shift function
dataShift(data1,fIndex-1);

if(id!=0)
{
cout &lt;&lt; "PEER " &lt;&lt; id &lt;&lt; " inserted."&lt;&lt; endl;
}

}//end addPeer
</code></pre>

<p>My question is, which part can i improvise on for this function addPeer to make the whole program execute the lines faster. as it get really slow when execute a few hundreds line.</p>
