Prompt Library › ⚙️ Technical › Profile and Optimize Code Performance
GPT-4o ⚙️ Technical Advanced

Profile and Optimize Code Performance

Share profiling data and code from [BOTTLENECK_FUNCTION] and get a step-by-step optimization plan with benchmarked improvements.

👁 5 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Profile and Optimize Code Performance

You are a performance engineering specialist. Optimize [BOTTLENECK_FUNCTION] in [LANGUAGE] based on the profiling data below.

## Profiling Data

```
[PASTE_PROFILE_OUTPUT_HERE]
```

**Profiling tool used:** [PROFILER_TOOL]
**Environment:** [CPU], [MEMORY], [LOAD_PATTERN]
**Performance target:** reduce execution from [CURRENT_TIME]ms to under [TARGET_TIME]ms

## Bottleneck Code

```
[PASTE_BOTTLENECK_CODE_HERE]
```

## Optimization Approach

Analyze and apply these strategies where applicable:
1. **Algorithmic** — improve time complexity from [CURRENT_BIG_O] by changing [ALGORITHM]
2. **Memory** — reduce allocations in [HOT_PATH] using [MEMORY_TECHNIQUE]
3. **Concurrency** — parallelize [PARALLELIZABLE_WORK] using [CONCURRENCY_PRIMITIVE]
4. **Caching** — memoize [PURE_FUNCTION] with [CACHE_STRATEGY]

## Output

1. Optimized code with comments explaining each change
2. Expected improvement estimate for each optimization
3. A benchmark script to measure before/after in [BENCHMARK_TOOL]

📝 Fill in the blanks

Replace these placeholders with your own content:

[BOTTLENECK_FUNCTION]
[LANGUAGE]
[PASTE_PROFILE_OUTPUT_HERE]
[PROFILER_TOOL]
[CPU]
[MEMORY]
[LOAD_PATTERN]
[CURRENT_TIME]
[TARGET_TIME]
[PASTE_BOTTLENECK_CODE_HERE]
[CURRENT_BIG_O]
[ALGORITHM]
[HOT_PATH]
[MEMORY_TECHNIQUE]
[PARALLELIZABLE_WORK]
[CONCURRENCY_PRIMITIVE]
[PURE_FUNCTION]
[CACHE_STRATEGY]
[BENCHMARK_TOOL]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.