The Research Report
Prompt Compression Benchmarker: The Tool That Cuts LLM Input Costs by 35-63% Without Flying Blind
Published: May 14, 2026
Most of your LLM bill comes from one place. Input tokens. The long documents, chat histories, codebases, and RAG contexts you stuff into the prompt window every single call.
Prompt compression is not a new idea. Libraries like LLMLingua, Selective Context, and TF-IDF truncation have been around for a while. But here is the problem nobody talks about. Every compression algorithm drops quality. The question is how much. And for your specific workload, which one drops the least.
That gap is exactly what Prompt Compression Benchmarker (PCB) fills. Published on DEV Community on May 6, 2026, PCB is an open-source Python tool that benchmarks every major prompt compression algorithm against your actual data. It shows you the exact quality trade-off for each compressor. It projects real dollar savings at your call volume. Then it hands you a one-line wrapper to deploy the winner in production.
No guesswork. No hoping your compressed prompt still works. Just measured, comparable numbers.
The Problem with "Just Compress It"
Here is how prompt compression usually goes in practice.
Someone on the team reads about LLMLingua. They install it. They set a compression rate of 0.5. They run a few manual tests. The outputs look fine. They ship it.
Three weeks later, customer support tickets start climbing. The RAG pipeline is returning answers that miss key details. A summarization feature starts dropping named entities. Nobody knows if the compressor caused it, because nobody measured quality before and after. They turn compression off and eat the token cost.
The issue is not that compression is bad. The issue is that compression without measurement is gambling.
Different algorithms destroy different kinds of information. TF-IDF truncation drops low-importance sentences, which works fine for general chat but can massacre a technical document. LLMLingua uses a smaller model to distill prompts, which preserves structure better but can hallucinate or merge facts. Selective Context uses self-information scoring, which is great for narrative text but may discard code identifiers.
You cannot know which one is right for your workload without running a controlled benchmark on your actual data. PCB does exactly that.
What PCB Actually Does
PCB answers two questions with hard numbers.
Which compressor preserves the most quality at a given token budget?
Benchmark mode runs all supported compressors against your data. It scores each one with task-specific proxy metrics, F1, ROUGE, BM25, plus an optional LLM-as-judge evaluation. You get a table showing token reduction, quality score, and quality drop percentage for every algorithm side by side.
How much money does that save at your actual call volume?
Cost projection mode takes your daily token volume and your model pricing. It gives you monthly and annual savings per compressor. You can see immediately whether the quality trade-off is worth the dollar reduction.
Then it gives you a one-line wrapper to deploy the answer.
The Compressors Under Test
PCB currently benchmarks five algorithms.
| Compressor | Method | Best For |
|---|---|---|
| TF-IDF | Drops low-importance sentences by term frequency | General chat, safe default |
| Selective Context | Self-information scoring via perplexity | Narrative text, high compression |
| LLMLingua | Small LM distillation, sentence-level pruning | Summarization, structural coverage |
| LLMLingua-2 | Token-level pruning with task-aware masking | RAG, code contexts, named entities |
| No Compression | Baseline for comparison | Your control group |
Each compressor has a configurable rate, the fraction of tokens to remove. A rate of 0.45 means keep 55% of the original tokens. PCB lets you test different rates to find your sweet spot.
Running the Benchmark
Installation takes under a minute.
# From source
git clone https://github.com/dakshjain-1616/Prompt-Compression-Benchmarker
cd Prompt-Compression-Benchmarker
pip install .
# Verify
pcb --help
The simplest run uses bundled sample data. No setup needed.
pcb run
For a real evaluation, you point it at your data and your workload.
# Target a specific task with cost projection
pcb run --task rag --max-samples 20 --daily-tokens 2000000 --cost-model claude-sonnet-4-6
# Add LLM-as-judge for deeper quality scoring
export OPENROUTER_API_KEY=sk-or-...
pcb run --llm-judge --judge-model claude-sonnet-4-6 --max-samples 10
Here is what the output looks like for a RAG task at 3 million tokens per day, priced at Claude Sonnet 4.6 rates.
RAG
Compressor Token Reduc % Proxy Score Proxy Drop % ms
no_compression 0.0% 0.2983 0.0% 0.3
tfidf ★ 40.1% 0.2519 +16.5% 12.1
selective_context 56.9% 0.1874 +34.4% 8.3
llmlingua 53.6% 0.2182 +28.1% 9.7
llmlingua2 45.0% 0.2204 +27.3% 11.2
Monthly Cost Projection claude-sonnet-4-6 · $3/1M · 3M tokens/day
tfidf 38.3% reduction $103/mo saved $1,240/yr
selective_context 57.5% reduction $155/mo saved $1,863/yr
llmlingua2 43.6% reduction $118/mo saved $1,413/yr
The star marks the Pareto-optimal compressor. In this case, TF-IDF gives the best balance, highest token reduction with a quality drop below the 20% threshold.
Why You Need the LLM Judge
The proxy scores, F1, ROUGE, BM25, are fast and free. But they are mechanical. They measure token overlap, not semantic correctness. They can miss cases where the compressed prompt drops a critical fact that changes the answer entirely.
The LLM-as-judge mode calls a real model, Claude Sonnet, GPT-4o, or any of 75+ supported models, to evaluate whether the compressed context still supports the correct answer. It reveals things proxy metrics completely hide.
Here is a real example from the project's documentation, RAG task, 5 samples, judged by Claude Sonnet 4.6.
| Compressor | Proxy Drop % | LLM Score | LLM Drop % |
|---|---|---|---|
| no_compression | 0.0% | 0.94 | 0.0% |
| tfidf | +23.7% | 0.40 | -57.4% |
| llmlingua2 | +29.9% | 0.70 | -25.5% |
| selective_context | +37.6% | 0.14 | -85.1% |
Look at that second row. TF-IDF showed only a 23.7% quality drop in proxy metrics. The LLM judge scored it at 0.40, a 57.4% drop. The proxy hid the severity. Meanwhile, LLMLingua-2 looked worse than TF-IDF in proxy scores, but the LLM judge rated it much higher at 0.70.
The rule of thumb is simple. Use proxy scores to compare many configurations quickly. Then LLM-judge the top two or three before you deploy anything to production.
Real Cost Savings
Compression only saves money on input tokens. Output tokens are unchanged. But input tokens dominate most workloads, especially RAG and long-context applications.
At 3 million input tokens per day on Claude Opus 4.7, the savings look like this.
| Compressor | Monthly Savings | Annual Savings |
|---|---|---|
| TF-IDF at 40% | $1,240 | $14,880 |
| LLMLingua-2 at 45% | $1,413 | $16,956 |
| Selective Context at 57% | $1,863 | $22,356 |
The break-even point depends on your model. Compression is most valuable on premium models. On cheap models like DeepSeek or Gemini Flash, the savings may not justify the complexity unless you are hitting context window limits.
One-Line Production Deployment
Once you have chosen a compressor, deploying it is one line of code.
from pcb.middleware import CompressingAnthropic
# Drop-in replacement for anthropic.Anthropic()
client = CompressingAnthropic(compressor="llmlingua2", rate=0.45)
response = client.messages.create(
model="claude-opus-4-7",
messages=[{"role": "user", "content": very_long_document}],
max_tokens=1024,
)
print(client.stats)
# CompressionStats(calls=47, tokens_saved=21,800, reduction=44.8%)
Everything else in your codebase stays the same. The wrapper intercepts outgoing messages, compresses user role messages over 100 tokens, passes system prompts and assistant history through unchanged, and tracks cumulative statistics.
There is an equivalent wrapper for OpenAI.
from pcb.middleware import CompressingOpenAI
client = CompressingOpenAI(compressor="tfidf", rate=0.40)
# Works with Chat Completions
response = client.chat.completions.create(
model="gpt-4.1",
messages=[{"role": "user", "content": long_context}]
)
# And the Responses API
response = client.responses.create(
model="codex-mini-latest",
input=long_codebase_context,
reasoning={"effort": "high"}
)
Claude Code and MCP Integration
PCB ships with an MCP server for Claude Code and the OpenAI Agents SDK. This adds four compression tools directly into your agent conversations.
Setup is one command.
claude mcp add pcb -s project -- python -m pcb.mcp_server
Then you can ask Claude Code things like.
- Compress this RAG context before sending it to the model.
- Estimate how much I would save compressing prompts on Claude Opus at 2,000 calls per day.
- What compressor should I use for my coding assistant with a 90% quality floor?
The same MCP server works with the OpenAI Agents SDK.
from agents import Agent, Runner
from agents.mcp import MCPServerStdio
async def main():
async with MCPServerStdio(
name="pcb",
params={"command": "python", "args": ["-m", "pcb.mcp_server"]},
) as pcb_server:
agent = Agent(
name="CostAwareAssistant",
model="codex-mini-latest",
mcp_servers=[pcb_server],
)
result = await Runner.run(
agent,
"Compress this codebase context and estimate savings: " + codebase_context
)
print(result.final_output)
Benchmarking Your Own Data
PCB accepts JSONL files with schemas for three task types.
RAG schema.
{
"id": "my_001",
"context": "<passage 300-1500 tokens>",
"question": "<specific question requiring the full context>",
"answer": "<short, precise answer string>"
}
Summarization schema.
{
"id": "my_001",
"article": "<article or document 300-800 tokens>",
"summary": "<2-3 sentence reference summary>"
}
Coding schema.
{
"id": "my_001",
"context": "<imports, helpers, type definitions — 400-800 tokens>",
"docstring": "<description of the function to implement>",
"solution": "<correct Python implementation>"
}
Run the benchmark on your data with one command.
pcb run --data-dir ./my_data --task rag --max-samples 50
Export results to JSON, CSV, or HTML for sharing with your team.
pcb run --data-dir ./my_data --output results.html
The HTML report includes Chart.js scatter plots, dark theme, and Pareto-optimal highlights.
The Full Workflow: From Benchmark to Production
Here is the recommended path.
Step 1: Benchmark on your actual data.
pcb run --data-dir ./my_data --max-samples 50 --task rag \
--daily-tokens 2000000 --cost-model claude-opus-4-7 \
--output benchmark.json
Step 2: LLM-judge the top candidates.
pcb run --data-dir ./my_data --compressor tfidf --compressor llmlingua2 \
--llm-judge --judge-model claude-sonnet-4-6 --max-samples 30
Step 3: Deploy the winner.
from pcb.middleware import CompressingAnthropic
client = CompressingAnthropic(compressor="llmlingua2", rate=0.40)
# Everything else in your codebase stays the same
Step 4: Monitor in production.
if client.stats.calls % 1000 == 0:
logger.info(
"pcb savings: calls=%d saved=%d tokens (%.1f%%) est_monthly=$%.0f",
client.stats.calls,
client.stats.tokens_saved,
client.stats.reduction_pct,
client.stats.monthly_savings_usd(price_per_million=15.0, daily_calls_estimate=2000),
)
When NOT to Use Compression
PCB is honest about limitations.
- Short prompts under 200 tokens. Overhead exceeds savings. PCB skips these automatically.
- Cheap models under $0.50 per million tokens. DeepSeek, Gemini Flash, GPT-4.1-mini. Savings are too small to justify complexity.
- High-precision tasks. Legal review, medical diagnosis. Verify your quality floor with the LLM judge first.
- Output-bottlenecked workloads. Compression only affects input tokens. If your cost is all on the output side, this will not help.
Why This Matters
The LLM cost conversation usually focuses on model selection and output optimization. But input tokens are the silent majority of most bills. A RAG pipeline sending 8,000 tokens of context per query, at 10,000 queries per day, is burning 80 million input tokens daily. At Claude Opus rates, that is $1,200 per day just in context.
Cutting that by 40-60% with a measured, benchmarked compressor is not a nice-to-have. It is a direct margin improvement.
But doing it without measurement is reckless. PCB gives you the numbers to make an informed choice. It turns prompt compression from guesswork into engineering.
The tool is open source, MIT licensed, and requires no GPU. If you are running LLMs in production at any scale, you should benchmark your prompts before you compress them.
Prompt Compression Benchmarker is available on GitHub and PyPI. Installation takes under a minute. A full benchmark run on sample data takes under five.