title: Why does Python3 run faster if it is negating vs XOR?
body: <p>I thought negating a word or XOR a word with <code>1</code> both should take 1 clock cycle of the processor, but if using Python3, the following code to count the parity of a word:</p>
  
  <pre><code>def parity(x: int) -&gt; int:
      p = 0
      while x:
          p = ~p
          x = x &amp; (x-1)
      return p &amp; 1
  </code></pre>
  
  <p>running against 10,000 test cases would report <code>4μs</code> average running time consistently, but if it is:</p>
  
  <pre><code>def parity(x: int) -&gt; int:
      p = 0
      while x:
          p = p ^ 1
          x = x &amp; (x-1)
      return p
  </code></pre>
  
  <p>then it is consistently <code>5μs</code>. It actually has one less operation at the end not needing to <code>&amp; 1</code>.</p>
  
  <p>Even </p>
  
  <pre><code>def parity(x: int) -&gt; int:
      p = 0
      while x:
          p += 1
          x = x &amp; (x-1)
      return p % 2
  </code></pre>
  
  <p>is consistently running for <code>4μs</code>. To test increment vs addition, I changed the <code>p += 1</code> to <code>p += 7</code> and it is again consistently <code>4μs</code>.  What is the reason negating, increment, or addition faster than XOR using Python3?  (it is on a Mac if it makes any difference).</p>