21 lines
945 B
Python
21 lines
945 B
Python
#!/usr/bin/env python3
|
|
"""Einheitlicher Testsatz Folge 19: 5000 kleine Dateien (zufaellige Bytes, 1 KiB bis 79 KiB,
|
|
Seed fest) in einem flachen Ordner plus eine 2-GiB-Datei. Zufallsbytes, damit keine
|
|
Kompression oder Deduplizierung einem Produkt hilft.
|
|
Aufruf: gen-testset.py ZIELORDNER"""
|
|
import os, random, sys
|
|
root = sys.argv[1]
|
|
small = os.path.join(root, 'small'); big = os.path.join(root, 'big')
|
|
os.makedirs(small, exist_ok=True); os.makedirs(big, exist_ok=True)
|
|
rnd = random.Random(19)
|
|
total = 0
|
|
for i in range(1, 5001):
|
|
n = rnd.randint(1024, 80895)
|
|
with open(os.path.join(small, f'doc-{i:05d}.bin'), 'wb') as f:
|
|
f.write(os.urandom(n))
|
|
total += n
|
|
with open(os.path.join(big, 'big.bin'), 'wb') as f:
|
|
chunk = 64 * 1024 * 1024
|
|
for _ in range(32): # 32 x 64 MiB = 2 GiB
|
|
f.write(os.urandom(chunk))
|
|
print(f'small: 5000 files, {total} bytes ({total/2**20:.1f} MiB); big: 2147483648 bytes (2.00 GiB)')
|