title: What could affect Python string comparison performance for strings over 64 characters?
body: <p>I'm trying to evaluate if comparing two string get slower as their length increases. My calculations suggest comparing strings should take an amortized constant time, but my Python experiments yield strange results:</p>
  
  <p>Here is a plot of string length (1 to 400) versus time in milliseconds. Automatic garbage collection is disabled, and <code>gc.collect</code> is run between every iteration.</p>
  
  <p><img src="https://i.stack.imgur.com/7HZg1.png" alt="Time vs string length"></p>
  
  <p>I'm comparing 1 million random strings each time, counting matches as follows.The process is repeated 50 times before taking the min of all measured times.</p>
  
  <pre><code>for index in range(COUNT):
      if v1[index] == v2[index]:
          matches += 1
      else:
          non_matches += 1
  </code></pre>
  
  <p>What might account for the sudden increase around length 64?</p>
  
  <p><strong>Note</strong>: The following snippet can be used to try to reproduce the problem assuming <code>v1</code> and <code>v2</code> are two lists of random strings of length <code>n</code> and COUNT is their length.</p>
  
  <pre><code>timeit.timeit("for i in range(COUNT): v1[i] == v2[i]",
    "from __main__ import COUNT, v1, v2", number=50)
  </code></pre>
  
  <p><strong>Further note</strong>: I've made two extra tests: comparing string with <code>is</code> instead of <code>==</code> suppresses the problem completely, and the performance is about 210ms/1M comparisons.
  Since interning has been mentioned, I made sure to add a white space after each string, which should prevent interning; that doesn't change anything. Is it something else than interning then?</p>