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>I'm a newbie, so I can't comment. An "answer" might be overkill, but it's all I can do for now. </p>

<p>My favorite thing for this is <a href="https://pypi.python.org/pypi/tqdm" rel="nofollow">tqdm</a>. It's minimally invasive, both code-wise and output-wise, and it gets the job done. </p>

python algorithm performance python-2.7