Prompt Details
Model
(claude-5-sonnet)
Token size
240
Example input
[Code Snippet & Tech Stack]: Python script reading a large CSV file and storing data in a database using slow loops
Example output
1. Bug & Vulnerability Audit:
- Reading entire 5GB CSV into memory causes Out-Of-Memory (OOM) crashes.
- Row-by-row SQL INSERT queries create severe database bottleneck.
2. Refactored Code (Python + Pandas):
import pandas as pd
from sqlalchemy import create_engine
def batch_process_csv(file_path: str, db_url: str, chunk_size: int = 10000):
engine = create_engine(db_url)
for chunk in pd.read_csv(file_path, chunksize=chunk_size):
chunk.to_sql('users', engine, if_exists='append', index=False)
3. Performance Improvements:
- Time Complexity: Reduced from O(N) single inserts to O(N/batch_size) chunked inserts.
- Execution time dropped from 12 minutes to 18 seconds.
4. Change Log:
- Added chunked CSV stream reading to keep memory footprint under 50MB.
- Implemented bulk insert via SQLAlchemy.
Get this prompt + 9 more with SelectFrom $14/mo · Cancel anytimeFrom $14/mo · Cancel anytime
View SelectBy purchasing this prompt, you agree to our terms of service
CLAUDE-5-SONNET
Instantly debug, optimize, and refactor code across multiple languages (Python, JS, SQL, React). Improves performance, fixes bugs, and enforces clean code standards.
...more
Added 1 week ago
