---
title: Prompt Management Performance Benchmark
description: Performance benchmark on Langfuse Prompt Management measuring latency of retrieving and compiling prompts.
---

# Langfuse Prompt Management Performance Test

This notebook conducts a performance benchmark on Langfuse Prompt Management by measuring the latency of retrieving and compiling a prompt without caching (cache_ttl_seconds=0) over 1,000 sequential executions.

In practice, this latency does not matter as the prompt is cached client-side in the SDKs. Learn more about caching in the [Langfuse Prompt Management documentation](https://langfuse.com/docs/prompt-management/features/caching).

The test accounts for network latency, so absolute values may vary based on geography and load. Use the histogram and summary statistics to compare relative improvements, such as between SDK versions or caching settings.

The test requires a prompt named `perf-test` to be set up in the authenticated project.

```python
%pip install langfuse
```

```python
import os

# Get keys for your project from the project settings page
# https://cloud.langfuse.com
os.environ.setdefault("LANGFUSE_PUBLIC_KEY", "");
os.environ.setdefault("LANGFUSE_SECRET_KEY", "");
os.environ.setdefault("LANGFUSE_BASE_URL", "https://cloud.langfuse.com"); # 🇪🇺 EU region
# Other Langfuse data regions include 🇺🇸 US: https://us.cloud.langfuse.com, 🇯🇵 Japan: https://jp.cloud.langfuse.com and ⚕️ HIPAA: https://hipaa.cloud.langfuse.com
```

```python
import time
import pandas as pd
import matplotlib.pyplot as plt
from tqdm.auto import tqdm

from langfuse import Langfuse

# Initialize Langfuse client from environment variables
langfuse = Langfuse()

assert langfuse.auth_check(), "Langfuse client not initialized – check your environment variables."
```

```python
N_RUNS = 1_000
prompt_name = "perf-test"

durations = []
for _ in tqdm(range(N_RUNS), desc="Benchmarking"):
    start = time.perf_counter()
    prompt = langfuse.get_prompt(prompt_name, cache_ttl_seconds=0)
    prompt.compile(input="test")  # minimal compile to include server‑side processing
    durations.append(time.perf_counter() - start)
    time.sleep(0.05)

durations_series = pd.Series(durations, name="seconds")
```

```python
stats = durations_series.describe(percentiles=[0.25, 0.5, 0.75, 0.99])
stats
```

Our last performance test

```
count    1000.000000
mean        0.039335 sec
std         0.014172 sec
min         0.032702 sec
25%         0.035387 sec
50%         0.037030 sec
75%         0.041111 sec
99%         0.068914 sec
max         0.409609 sec
```

```python
plt.figure(figsize=(8,4))
plt.hist(durations_series, bins=30)
plt.xlabel("Execution time (sec)")
plt.ylabel("Frequency")
plt.show()
```

Our last performance test

![Chart](https://langfuse.com/images/docs/prompt-performance-chart.png)

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/resources/engineering/prompt-management-performance-benchmark.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx langfuse-cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
