I've a python script which loads data from 10k - 12k files and performs some operations. Sometime, this process takes hours. This such cases, I would like to see how much progress has been made by the python script.
Let's say if I'm loading 10,000 files using for loop, I don't want to do something like:
if n % 100 == 0:
print("%d steps completed!" % n)
as this will unnecessarily evaluate the if condition for thousands of times. I know that the total cost of this if statement will still be small compared to hours it takes to run the script, however, I was curious if python has any efficient feature to keep track of the progress.
print()every 100 files. You have correctly recognized that theifstatement will cost next to nothing compared to all the IO you're doing, so you're trying to solve a non-issue.n+1takes already 30 ns. This is close to the minimum time of an instruction taken by the CPython interpreter. If you want a faster code, then you definitively need not to use Python (and more especially CPython). Loading a file should take far more than 1000 ns whatever the target system (it require 3 expensive syscalls).sqlite3module