Created
April 28, 2022 09:51
-
-
Save misebox/206da43f89941afdc95698688c12ddfc to your computer and use it in GitHub Desktop.
chunk and logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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