Datatoy Logo

Batching

Group items to saturate your GPU or database

`.batch(n)` accumulates `n` items before emitting them as a list. `.temporal_batch(s)` groups everything arriving within `s` seconds — perfect for real-time streams (audio, sensors, WebSocket).

python
from olympipe import Pipeline
import time

# Batch fixe : regrouper 64 items avant traitement
results = (
    Pipeline(image_paths)           # 10 000 images
    .task(load_image, count=4)      # chargement parallèle
    .batch(64)                      # groupe en batches
    .task(model.predict)            # inférence GPU
    .wait_for_result()
)

# Batch temporel : fenêtre glissante de 500ms
results = (
    Pipeline(sensor_stream)
    .task(parse_frame)
    .temporal_batch(0.5)            # tout ce qui arrive en 500ms
    .task(aggregate)
    .wait_for_result()
)

Performance

10 000 images, GPU inference

No batching 50.0s
batch=16 12.0s
batch=64 3.2s
batch=128 2.1s
🚀 23.8× faster

How it works

Without batching, each item triggers a separate GPU round-trip. With a batch of 64, a single call processes 64 images — the fixed GPU latency is amortized over 64× more work.

Related examples