The method
Paste a code snippet into the prompt box. Specify the programming language and runtime environment. Ideally, this prompt works best with functions/methods under 200 lines. Avoid very general descriptions; be specific about your performance concerns.
The prompts
Prompt 1
Analyze the following Python code for performance bottlenecks, assuming it will be run in a standard CPython 3.9 environment. Focus on identifying areas where algorithmic complexity or inefficient data structures may be causing slowdowns. Provide specific suggestions for improvement, including alternative algorithms or data structures, and estimate the potential performance gains. Also consider the readability and maintainability of suggested changes:
```python
def process_data(data):
results = []
for item in data:
if item not in results:
results.append(item)
return results
```
```python
def process_data(data):
results = []
for item in data:
if item not in results:
results.append(item)
return results
```
Prompt 2
Review the following JavaScript code, which is intended for execution in a Node.js v16 environment. The goal is to identify and suggest remedies for potential performance bottlenecks, particularly those related to synchronous operations, blocking I/O, or memory leaks. Assume a large input dataset. Provide detailed advice on how to leverage asynchronous programming techniques, optimize database queries (if applicable), and reduce memory consumption. Analyze for worst case time complexity.
```javascript
function fetchDataAndProcess(ids) {
let results = [];
for (let i = 0; i < ids.length; i++) {
const data = db.querySync(`SELECT * FROM table WHERE id = ${ids[i]}`);
results.push(processSync(data));
}
return results;
}
```
```javascript
function fetchDataAndProcess(ids) {
let results = [];
for (let i = 0; i < ids.length; i++) {
const data = db.querySync(`SELECT * FROM table WHERE id = ${ids[i]}`);
results.push(processSync(data));
}
return results;
}
```