title: Why does the ipython magic function `%timeit -n1 code_block` execute `code_block` multiple times?
body: <p>I am trying to run a particular test multiple times in <code>ipython</code> using the
  <code>%timeit</code> magic function. For demonstration purposes, I will just use <code>-n1</code> instead of
  <code>-n3</code> here, and use a simple <code>print(1)</code> function. </p>
  
  <p>The <code>%%timeit</code> and the <code>%timeit</code> help says the following: </p>
  
  <pre><code>Options: -n&lt;N&gt;: execute the given statement &lt;N&gt; times in a loop. If this
  value is not given, a fitting value is chosen.
  
  -r&lt;R&gt;: repeat the loop iteration &lt;R&gt; times and take the best result.
  Default: 3 (the 3 here is a typo in ipython, for which I have submitted a
  PR)
  </code></pre>
  
  <p>However, if I do the following:</p>
  
  <pre><code>%%timeit -n1
  print(1)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>%timeit -n1 print(1)
  </code></pre>
  
  <p>it actually prints <code>1</code> 7 times in a row as follows</p>
  
  <pre><code>In[1]: %timeit -n1 print(1)
  1
  1
  1
  1
  1
  1
  1
  32.8 µs ± 38.7 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
  </code></pre>
  
  <p>I was expecting that because of the definition of <code>%%timeit</code>/<code>%timeit</code> it would
  run the <code>cell</code> or <code>code</code> just once.</p>
  
  <p>I have read this post: <a href="https://stackoverflow.com/a/45375047/4752883">https://stackoverflow.com/a/45375047/4752883</a>
  which gives some examples of how <code>%%timeit</code> runs and the actual source code of <code>ipython</code> magic function <code>%%timeit</code>
  here: <a href="https://github.com/ipython/ipython/blob/ec3d1a11bf26a0962cb2cf55ba263b12ac023183/IPython/core/magics/execution.py#L944" rel="noreferrer">https://github.com/ipython/ipython/blob/ec3d1a11bf26a0962cb2cf55ba263b12ac023183/IPython/core/magics/execution.py#L944</a></p>
  
  <p>where they define 2 types of loops: 1) <code>-n&lt;N&gt;</code> and 2) <code>-r&lt;R&gt;</code>. </p>
  
  <p>If I just use <code>-n1</code>, it seems that it also assumes that I have used <code>-r7</code>, i.e.
  <code>-n1</code> defaults to <code>-n1 -r7</code>. This means that even though I want it to run for
  exactly 1 run, it will still run the <code>code_block</code> 7 times as per
  <a href="https://github.com/ipython/ipython/blob/ec3d1a11bf26a0962cb2cf55ba263b12ac023183/IPython/core/magics/execution.py#L1021" rel="noreferrer">https://github.com/ipython/ipython/blob/ec3d1a11bf26a0962cb2cf55ba263b12ac023183/IPython/core/magics/execution.py#L1021</a>
  unless I also specify <code>-n1 -r1</code>.</p>
  
  <h2>Questions:</h2>
  
  <ol>
  <li>Why are there 2 different ways to running the <code>code_block</code> using <code>-n&lt;N&gt;</code> and
  <code>-r&lt;R&gt;</code>?</li>
  <li>What is the difference between <code>-n&lt;N&gt;</code> and <code>-r&lt;R&gt;</code> and why is this
  necessary?</li>
  </ol>