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

# Fixed batch: group 64 items before processing
results = (
    Pipeline(image_paths)           # 10 000 images
    .task(load_image, count=4)      # parallel loading
    .batch(64)                      # group into batches
    .task(model.predict)            # GPU inference
    .wait_for_result()
)

# Temporal batch: 500ms sliding window
results = (
    Pipeline(sensor_stream)
    .task(parse_frame)
    .temporal_batch(0.5)            # everything arriving within 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