title: Which is faster, string.empty() or string.size() == 0?
body: <p>Recently, during a discussion I was asked by a fellow programmer to do some code changes. I had something like:</p>
  
  <pre><code>if( mystring.size() == 0)
      // do something
  else
      // do something else 
  </code></pre>
  
  <p>The discussion was regarding the use of <code>mystring.empty()</code> to validate if the string is empty. Now, I agree that it can be argued that <code>string.empty()</code> is more verbose and readable code, but are there any performance benefits to it?  </p>
  
  <p>I did some digging and found these 2 answers pertaining to my question:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/a/483361/355722">Implementation from basic_string.h</a></li>
  <li><a href="https://stackoverflow.com/a/483517/355722">SO Answer that points to ISO Standard</a> - <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/wp/html/oct97/lib-strings.html#lib.string.capacity" rel="nofollow noreferrer">here</a></li>
  </ul>
  
  <p>Both the answers buttress my claim that the <code>string.empty()</code> is just more readable and doesn't offer any performance benefits, compared to <code>string.size() == 0</code>.  </p>
  
  <p>I still want to be sure, if there are any implementations of <code>string</code> that keep an <em>internal boolean flag</em> to validate if a string is empty or not?   </p>
  
  <p>Or there are other ways that some implementations use, that would nullify my claim??</p>