title: How come these Python codes perform so much differently
body: <p>Please look at the following code to solve the same set of problem, I do not think that mentioning the problem would anyhow help the purpose, it's yet another iteration of the <a href="http://en.wikipedia.org/wiki/Josephus_problem" rel="nofollow">Josephus problem</a>:</p>
  
  <p>Solution 1:</p>
  
  <pre><code>import sys
  from math import log
  
  cases= int(sys.stdin.readline())
  current= 0
  while current &lt; cases:
      current += 1
      n = int(sys.stdin.readline())
      print 2*(n - 2**(int(log(n,2))))+1
  </code></pre>
  
  <p>This solution solves the given 10 test cases in cumulative 1.0912 seconds and consumes 4360KiB of memory.</p>
  
  <p>Solution 2:</p>
  
  <pre><code>def josephus_2( n ):
      from math import log
      return 2*(n - 2**(int(log(n,2))))+1
  
  import sys
  cases= int(sys.stdin.readline())
  current= 0
  while current &lt; cases:
      current += 1
      n = int(sys.stdin.readline())
      print josephus_2( n )
  </code></pre>
  
  <p>this solution solves the same 10 test cases in a total of 1.0497 seconds and 640KiB of memory.</p>
  
  <p>Being a Python n00b I was wondering, while according to the online judge I earn same points for both, but what makes the solution 2 more faster than 1 and much more memory efficient? I know that the time difference can sound very less, but at the same time ranks me first on the fastest solution, even faster than c/c++/perl submissions</p>
  
  <p><a href="http://i.imgur.com/wsF8riO.png" rel="nofollow">Can this Screenshot help?</a></p>