title: time.time vs. timeit.timeit
body: <p>Sometimes, I like to time how long it takes parts of my code to run.  I've checked a lot of online sites and have seen, at large, two main ways to do this.  One is using <code>time.time</code> and the other is using <code>timeit.timeit</code>.</p>
  
  <p>So, I wrote a very simple script to compare the two:</p>
  
  <pre><code>from timeit import timeit
  from time import time
  start = time()
  for i in range(100): print('ABC')
  print(time()-start, timeit("for i in range(100): print('ABC')", number=1))
  </code></pre>
  
  <p>Basically, it times how long it takes to print "ABC" 100 times in a for-loop.  The number on the left is the results for <code>time.time</code> and the number on the right is for <code>timeit.timeit</code>:</p>
  
  <pre><code># First run
  0.0 0.012654680972022981
  # Second run
  0.031000137329101562 0.012747430190149865
  # Another run
  0.0 0.011262325239660349
  # Another run
  0.016000032424926758 0.012740166697164025
  # Another run
  0.016000032424926758 0.0440628627381413
  </code></pre>
  
  <p>As you can see, sometimes, time.time is faster and sometimes it's slower.  Which is the better way (more accurate)?</p>