| 1 |
import hashlib |
| 2 |
import os |
| 3 |
import pathlib |
| 4 |
from multiprocessing.pool import ThreadPool |
| 5 |
|
| 6 |
from rich.progress import Progress |
| 7 |
|
| 8 |
POOL = ThreadPool(32) |
| 9 |
|
| 10 |
DATA_DIR = pathlib.Path(os.environ.get("CAIO_BENCH_DATA", "data")) |
| 11 |
|
| 12 |
|
| 13 |
def gen_data(file_id): |
| 14 |
seed = os.urandom(64) |
| 15 |
hasher = hashlib.sha512() |
| 16 |
|
| 17 |
with open(DATA_DIR / f"{file_id}.bin", "wb+") as fp: |
| 18 |
for _ in range(100000): |
| 19 |
hasher.update(seed) |
| 20 |
seed = hasher.digest() |
| 21 |
fp.write(seed) |
| 22 |
|
| 23 |
|
| 24 |
def main(): |
| 25 |
files = 128 |
| 26 |
DATA_DIR.mkdir(parents=True, exist_ok=True) |
| 27 |
|
| 28 |
with Progress() as progress: |
| 29 |
task = progress.add_task("Generating...", total=files) |
| 30 |
for _ in POOL.imap_unordered(gen_data, range(files)): |
| 31 |
progress.advance(task) |
| 32 |
|
| 33 |
|
| 34 |
if __name__ == "__main__": |
| 35 |
main() |