title: Strings and unordered_map running slow
body: <p>Here is 2 functions in my code that are running REALLY SLOW. 
  Basically i read in a document name, open the document, then process it one word at a time. I need to split up the document into sentences, and give each sentence a hash table that represents the number of times the word appears in the sentence.  I also need to keep track of all the new words, and a hash table for the total document.</p>
  
  <p>When i run my code now on 10 documents, that have a total of 8000word, and 2100 uniq words it takes about 8000+ seconds to run... almost 1 second per word.</p>
  
  <p>can you tell me how long <code>if(istream.good())</code> should take?</p>
  
  <p>Or, if you can tell when what is delaying my code.  Please let me know if a section is not clear, i will help.</p>
  
  <p>P.S. You can see in the code where i have a <code>start = clock()</code> and <code>end = clock()</code> commented it constantly returns &lt; 1ms.  And that is mind-boggleing</p>
  
  <pre><code>void  DocProcess::indexString(string sentenceString, hash * sent){
  
  stringstream iss;
  
  string word;
  iss.clear();
  iss &lt;&lt; sentenceString;
  
  while(iss.good())
  {
  
      iss &gt;&gt; word;
      word = formatWord(word);
  
      std::unordered_map&lt;std::string,int&gt;::const_iterator IsNewWord = words.find(word);
  
      if(IsNewWord == words.end())
      {
          std::pair&lt;std::string,int&gt; newWordPair (word,0);
          std::pair&lt;std::string,int&gt; newWordPairPlusOne (word,1);
  
          words.insert(newWordPair);
          sent-&gt;insert(newWordPairPlusOne);
      }
      else
      {
          std::pair&lt;std::string,int&gt; newWordPairPlusOne (word,1);
          sent-&gt;insert(newWordPairPlusOne);
      }
  }
  </code></pre>
  
  <p>}
  void DocProcess::indexFile(string iFileName){</p>
  
  <pre><code>hash newDocHash;
  hash newSentHash;
  scoreAndInfo sentenceScore;
  scoreAndInfo dummy;
  
  fstream iFile;
  fstream dFile;
  string word;
  string newDoc;
  string fullDoc;
  int minSentenceLength = 5;
  int docNumber = 1;
  int runningLength = 0;
  int ProcessedWords = 0;
  stringstream iss;
  
  iFile.open(iFileName.c_str());
  
  if(iFile.is_open())
  {
      while(iFile.good())
      {
          iFile &gt;&gt; newDoc;
          dFile.open(newDoc.c_str());
          DocNames.push_back(newDoc);
  
          if(dFile.is_open())
          {
              scoreAndInfo documentScore;
              //iss &lt;&lt; dFile.rdbuf();
              while(dFile.good())
              {
                  //start = clock();
                  dFile &gt;&gt; word;
                  ++ProcessedWords;
  
                  std::unordered_map&lt;std::string,int&gt;::const_iterator IsStopWord = stopWords.find(word);
  
  
                  if(runningLength &gt;= minSentenceLength &amp;&amp; IsStopWord != stopWords.end() || word[word.length()-1] == '.')
                  {
  
                      /* word is in the stop list, process the string*/
                      documentScore.second.second.append(" "+word);
                      sentenceScore.second.second.append(" "+word);
  
                      indexString(sentenceScore.second.second, &amp;sentenceScore.second.first);
  
                      sentenceScore.first=0.0;
                      SentList.push_back(sentenceScore);
                      sentenceScore.second.first.clear(); //Clear hash
                      sentenceScore.second.second.clear(); // clear string
                      //sentenceScore = dummy;
                      runningLength = 0;
                  }
                  else
                  {
                      ++runningLength;
                      sentenceScore.second.second.append(" "+word);
                      documentScore.second.second.append(" "+word);
  
                  }
                  //end = clock();
                      system("cls");
                      cout    &lt;&lt; "Processing doc number: " &lt;&lt; docNumber &lt;&lt; endl
                          &lt;&lt; "New Word count: " &lt;&lt; words.size() &lt;&lt; endl
                          &lt;&lt; "Total words: " &lt;&lt; ProcessedWords &lt;&lt; endl;
                          //&lt;&lt; "Last process time****: " &lt;&lt; double(diffclock(end,start)) &lt;&lt; " ms"&lt;&lt; endl;
  
              }
              indexString(documentScore.second.second, &amp;documentScore.second.first);
              documentScore.first=0.0;
              DocList.push_back(documentScore);
              dFile.close();
              //iss.clear();
              //documentScore = dummy;
              ++docNumber;
              //end = clock();
              system("cls");
              cout    &lt;&lt; "Processing doc number: " &lt;&lt; docNumber &lt;&lt; endl
                  &lt;&lt; "Word count: " &lt;&lt; words.size();
                  //&lt;&lt; "Last process time: " &lt;&lt; double(diffclock(end,start)) &lt;&lt; " ms"&lt;&lt; endl;
  
          }
      }
  
      iFile.close();
  }
  else{ cout &lt;&lt; "Unable to open index file: "&lt;&lt;endl &lt;&lt;iFileName &lt;&lt; endl;}
  </code></pre>
  
  <p>}
  `</p>