Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Unstructured IO Unstructured Measure Execution Time

From Leeroopedia
Revision as of 11:54, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Unstructured_IO_Unstructured_Measure_Execution_Time.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Performance, Benchmarking
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for benchmarking partition execution time with warmup and multiple iterations.

Description

The measure_execution_time function runs the partition function multiple times on a given document, computes the average execution time, and returns the result. It is accompanied by warm_up_process which primes the runtime before timed iterations. The benchmark orchestration scripts (benchmark.sh, benchmark-local.sh) automate running benchmarks across multiple documents and recording results to CSV.

Usage

Import this function when you need programmatic benchmarking of partition operations. Use the benchmark shell scripts for automated multi-document benchmarking with CSV output.

Code Reference

Source Location

  • Repository: unstructured
  • File: scripts/performance/time_partition.py (lines 8-38)
  • File: scripts/performance/benchmark-local.sh (lines 1-43)

Signature

def warm_up_process(filename):
    """Run a warmup partition to prime caches and imports.

    Args:
        filename: Path to a small warmup document.
    """

def measure_execution_time(filename, iterations, strategy):
    """Measure average partition execution time.

    Args:
        filename: Path to the document to benchmark.
        iterations: Number of timed iterations.
        strategy: Partition strategy string.
    Returns:
        Average execution time in seconds.
    """
# benchmark-local.sh orchestration
# Runs benchmarks on all documents in scripts/performance/docs/
# Outputs CSV: {date}_benchmark_results_{instance}_{stats}_{git_hash}.csv
# Columns: Test File, Iterations, Average Execution Time (s)

Import

from scripts.performance.time_partition import measure_execution_time, warm_up_process

I/O Contract

Inputs

Name Type Required Description
filename str Yes Path to document file to benchmark
iterations int Yes Number of timed iterations (default 2-3)
strategy str Yes Partition strategy (auto, fast, hi_res, ocr_only)

Outputs

Name Type Description
return float Average execution time in seconds
CSV (via benchmark scripts) file Benchmark results with columns: Test File, Iterations, Average Execution Time (s)

Usage Examples

Programmatic Benchmarking

from scripts.performance.time_partition import measure_execution_time, warm_up_process

# Warmup
warm_up_process("scripts/performance/warmup_docs/warmup.txt")

# Benchmark
avg_time = measure_execution_time(
    filename="scripts/performance/docs/book-war-and-peace-1p.txt",
    iterations=3,
    strategy="fast",
)
print(f"Average time: {avg_time:.2f}s")

Run Benchmark Suite

# Local benchmark (all documents in docs/ directory)
./scripts/performance/benchmark-local.sh

# CI benchmark (with S3 publishing)
PUBLISH_RESULTS=true INSTANCE_TYPE="c5.2xlarge" ./scripts/performance/benchmark.sh

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment