title: Profiled performance of len(set) vs. set.__len__() in Python 3
body: <p>While profiling my Python's application, I've discovered that <code>len()</code> seems to be a very expensive one when using sets. See the below code:</p>
  
  <pre><code>import cProfile
  
  def lenA(s):
      for i in range(1000000):
          len(s);
  
  def lenB(s):
      for i in range(1000000):
          s.__len__();
  
  def main():
      s = set();
      lenA(s);
      lenB(s);
  
  if __name__ == "__main__":
      cProfile.run("main()","stats");
  </code></pre>
  
  <p>According to profiler's stats below, <code>lenA()</code> seems to be 14 times slower than <code>lenB()</code>:</p>
  
  <pre><code> ncalls  tottime  percall  cumtime  percall  filename:lineno(function)
        1    1.986    1.986    3.830    3.830  .../lentest.py:5(lenA)
  1000000    1.845    0.000    1.845    0.000  {built-in method len}
        1    0.273    0.273    0.273    0.273  .../lentest.py:9(lenB)
  </code></pre>
  
  <p>Am I missing something? Currently I use <code>__len__()</code> instead of <code>len()</code>, but the code looks dirty :(</p>