Use when the user asks to make something faster, try many variants, run recursive optimization, benchmark latency/throughput/cost, or choose the best implementation by repeated measured tests.
git clone https://github.com/affaan-m/ECC.git--- name: benchmark-optimization-loop description: Use when the user asks to make something faster, try many variants, run recursive optimization, benchmark latency/throughput/cost, or choose the best implementation by repeated measured tests. license: MIT metadata: origin: ECC tools: Read, Write, Edit, Bash, Grep, Glob --- # Benchmark Optimization Loop Use this skill to convert "make it 20x faster" or "try 50 recursive optimizations" into a bounded measured loop that can actually improve a system. ## Required Baseline Do not optimize until these exist: - the operation being optimized; - the correctness gate that must stay green; - the metric: wall time, p95 latency, rows/sec, cost/run, memory, error rate; - the current baseline; - the search budget: max variants, max time, max spend, max data impact. If the user asks for an unrealistic target, keep the ambition but make the loop bounded and measurable. ## Loop 1. Measure the baseline. 2. Identify bottlenecks from evidence. 3. Generate variants that test one hypothesis each. 4. Run variants with the same input shape. 5. Reject variants that fail correctness, safety, or reproducibility. 6. Promote the fastest safe variant. 7. Codify the winning path in a script, command, test, config, or doc. 8. Rerun the baseline and winner to confirm the delta. ## Variant Table Track variants like this: ```text Variant | Hypothesis | Command | Time | Correct? | Notes baseline | current path | npm run job | 120s | yes | stable batch-500 | fewer round trips | npm run job -- --batch 500 | 42s | yes | winner parallel-8 | more workers | npm run job -- --workers 8 | 31s | no | rate limited ``` ## Recursive Search For recursive or hyperparameter work: - persist every run to a ledger; - compare against the prior accepted winner, not only the previous run; - keep a holdout or replay check; - stop when improvement is within noise, correctness fails, cost exceeds the budget, or the search starts changing more variables than it can explain. Use phrases like "best measured safe variant" instead of "global optimum" unless the search space was actually exhaustive. ## Promotion Gate A variant cannot become the new default until: - correctness tests pass; - the performance delta is repeated or explained; - rollback is obvious; - the change is encoded in source control or a durable runbook; - the final summary includes exact commands and measurements.
["Define the baseline: Start with your current implementation and document its performance metrics (e.g., latency, throughput, cost). Use tools like `locust`, `Apache Bench`, or custom scripts to measure.","Generate variants: Brainstorm 5-7 alternative approaches (e.g., algorithm changes, hardware optimizations, or architectural shifts). Include at least one \"wildcard\" idea (e.g., GPU offload or precomputation).","Benchmark systematically: Use the same benchmark tool and workload for all variants. Record metrics (mean, median, P95, P99) and note any outliers or anomalies.","Compare and select: Use statistical methods (e.g., paired t-tests) to compare variants. Focus on the top 3 performers for further optimization.","Recursively optimize: Apply the same loop to the best variant (e.g., hyperparameter tuning, parallelization, or caching). Iterate until gains plateau or meet your target.","Tip: Automate the loop with scripts (e.g., Python + Jupyter) to reduce manual effort. Use tools like `Optuna` for hyperparameter optimization or `Ray Tune` for distributed benchmarking."]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/affaan-m/ECC/tree/main/skills/benchmark-optimization-loopCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Design and execute a benchmark-optimization loop to improve the performance of [TASK/SYSTEM]. Start with [BASELINE_IMPLEMENTATION] and generate 5-7 alternative variants (e.g., algorithm changes, parameter tuning, hardware optimizations, or code refactoring). For each variant, measure [METRIC: e.g., latency, throughput, cost, accuracy] using [BENCHMARK_TOOL: e.g., Apache Bench, Locust, custom Python script]. Compare results using [STATISTICAL_METHOD: e.g., mean, median, 95th percentile] and select the top 3 performers. Then, recursively optimize the best variant by [OPTIMIZATION_STRATEGY: e.g., gradient descent for hyperparameters, loop unrolling, or parallelization]. Document the final optimized solution with before/after metrics and a brief explanation of the improvements. Use [TOOLS: e.g., Python, Jupyter Notebook, or cloud-based load testing] as needed.
### Benchmark-Optimization Loop: Optimizing a Python API Endpoint **Baseline Implementation:** A Flask API endpoint (`/process_data`) that processes a 10MB JSON payload by applying a series of transformations (e.g., filtering, aggregation, and sorting) using nested loops. Initial benchmarking with `locust` (100 concurrent users) showed: - **Latency (P95):** 1250ms - **Throughput:** 80 requests/sec - **CPU Usage:** 85% (single-core) **Generated Variants:** 1. **Vectorized Pandas:** Replaced nested loops with Pandas operations. Benchmarked at 450ms (P95) and 280 req/sec. 2. **Numba JIT:** Added `@njit` decorator to critical functions. Benchmarked at 320ms (P95) and 310 req/sec. 3. **Cython:** Compiled critical sections with Cython. Benchmarked at 280ms (P95) and 350 req/sec. 4. **Multiprocessing:** Split workload across 4 CPU cores. Benchmarked at 210ms (P95) and 470 req/sec. 5. **AsyncIO:** Used `async`/`await` for I/O-bound tasks. Benchmarked at 190ms (P95) and 520 req/sec. 6. **GPU Offload:** Moved transformations to a CUDA kernel (using Numba). Benchmarked at 150ms (P95) and 660 req/sec. 7. **Precomputation:** Cached frequent query results in Redis. Benchmarked at 120ms (P95) and 830 req/sec. **Top 3 Performers:** 1. Precomputation (Redis) – 120ms (P95), 830 req/sec 2. GPU Offload (Numba CUDA) – 150ms (P95), 660 req/sec 3. AsyncIO – 190ms (P95), 520 req/sec **Recursive Optimization:** Focused on the precomputation variant (Redis). Tested different cache invalidation strategies: - **TTL-based (5min):** 120ms (P95), 830 req/sec - **LRU Cache (size=1000):** 110ms (P95), 910 req/sec - **Write-through Cache:** 95ms (P95), 1050 req/sec **Final Optimized Solution:** - **Implementation:** Write-through caching with Redis + async I/O for cache misses. - **Metrics:** 95ms (P95 latency), 1050 req/sec, 45% CPU usage. - **Improvement:** 92% faster (P95) and 13x higher throughput vs. baseline. **Recommendation:** Deploy the write-through Redis cache with async I/O. Monitor cache hit ratio and adjust TTL as needed. Further gains may require sharding the Redis instance for higher throughput.
skills-collection
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan