Efficiency when printing progress updates, print x vs if x%y==0: print x
<p>I am running an algorithm which reads an excel document by rows, and pushes the rows to a SQL Server, using Python. I would like to print some sort of progression through the loop. I can think of two very simple options and I would like to know which is more lightweight and why.
Option A:</p>

<pre><code>for x in xrange(1, sheet.nrows):
    print x
    cur.execute() # pushes to sql
</code></pre>

<p>Option B:</p>

<pre><code>for x in xrange(1, sheet.nrows):
    if x % some_check_progress_value == 0:
        print x
    cur.execute() # pushes to sql
</code></pre>

<p>I have a feeling that the second one would be more efficient but only for larger scale programs. Is there any way to calculate/determine this? </p>

<p>Using the modulus check (counter % N == 0) is almost free compared print and a  great solution if you run a high frequency iteration (log a lot).
Specially if you does not need to print for each iteration but want some feedback along the way.</p>

python algorithm performance python-2.7