Skip to content

Instantly share code, notes, and snippets.

@misebox
Created April 28, 2022 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misebox/206da43f89941afdc95698688c12ddfc to your computer and use it in GitHub Desktop.
Save misebox/206da43f89941afdc95698688c12ddfc to your computer and use it in GitHub Desktop.
chunk and logs
import time
import alog
def chunks(l, n, logging_step=10):
count = 0
total = len(l)
start_time = time.perf_counter()
for i in range(0, len(l), n):
chunk = l[i:i + n]
yield chunk
count += len(chunk)
ratio = count * 100 // total
if (count * logging_step // total) - ((count - len(chunk)) * logging_step // total) >= 1:
elapsed = time.perf_counter() - start_time
alog.info(f'processing ... {count}/{total} ({ratio}%) (took: {elapsed:0.6f} usec)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment