title: Why is it faster to compare strings that match than strings that do not?
body: <p>Here are two measurements:</p>
  <pre><code>timeit.timeit('&quot;toto&quot;==&quot;1234&quot;', number=100000000)
  1.8320042459999968
  timeit.timeit('&quot;toto&quot;==&quot;toto&quot;', number=100000000)
  1.4517491540000265
  </code></pre>
  <p>As you can see, comparing two strings that match is faster than comparing two strings with the same size that do not match.
  This is quite disturbing: During a string comparison, I believed that Python was testing strings character by character, so <code>&quot;toto&quot;==&quot;toto&quot;</code> should be longer to test than <code>&quot;toto&quot;==&quot;1234&quot;</code> as it requires four tests against one for the non-matching comparison. Maybe the comparison is hash-based, but in this case, timings should be the same for both comparisons.</p>
  <p>Why?</p>