LLM Prompts

Strategic Code Refinement for Performance Enhancement

Refactors code for improved performance based on identified bottlenecks.

The method

Use this prompt to guide code refactoring for optimal speed. Input: the existing code. Context: performance bottlenecks identified via profiling. Expected Output: Refactored code with explanations. Condition: Apply after profiling.

The prompts

Prompt 1
Analyze the following Python code for potential performance bottlenecks. Focus on areas that could be optimized for speed and memory usage. Provide specific suggestions for improvement, including code snippets demonstrating the proposed changes. Explain the reasoning behind each suggestion and estimate the potential performance gains. The code processes a large dataset, sorts the data using a custom comparison function, and performs several filtering operations based on complex criteria. Consider aspects such as algorithmic complexity, data structures, and the use of built-in functions versus custom implementations. Also, check for areas where memoization, vectorization (using libraries like NumPy), or parallelization (using libraries like multiprocessing) could be applied to speed up the execution. The code is:

```python
# Paste your python code here
```
Prompt 2
You are a senior software architect tasked with reviewing code for performance and maintainability. A junior developer has written the following code to process financial transactions. Identify any performance bottlenecks, memory leaks, or areas where the code can be simplified and made more efficient. Provide detailed recommendations, including specific code examples, explaining how to address these issues. Consider factors such as the use of appropriate data structures, the avoidance of unnecessary loops or function calls, and the efficient handling of large datasets. Also, evaluate the code's scalability and suggest changes that would allow it to handle a larger volume of transactions without significant performance degradation. The code is:

```java
// Paste your java code here
```