Some nanosecond for timeit with no statement

Is it normal? How can be taken into account in microbenchmarks, as a systematic error?

marco@buzz:~/sources/cpython-frozendict$ ../cpython_build_normal/python -VV
Python 3.10.0a0 (heads/master-dirty:c75330605d, Sep 13 2020, 00:47:49) 
[GCC 10.1.1 20200718]
marco@buzz:~/sources/cpython-frozendict$ ../cpython_build_normal/python -m timeit -n 500000000 ""
500000000 loops, best of 5: 6.03 nsec per loop

Yes, there’s overhead in simply iterating -n times. It’s normal, as you can read in the timeit docstring and python -m timeit --help. If you’re comparing your code to the pass statement, subtract the numbers you get for pass.

1 Like

So if I don’t have passes in code, I do not have to subtract this delta time?
Is too much a problem to remove this time in timeit by default? Maybe I can help a little (when I have time :P)

The code does not hide that on purpose as the baseline is representative of more than just the empty for loop (it also measures VM overhead that will also appear on non-empty statements). Every user should decide if they want to subtract the baseline or not.

2 Likes