A Python project with intentionally inefficient code designed for optimization practice and performance improvement exercises.
This repository contains deliberately poorly written Python code that demonstrates common performance anti-patterns and inefficiencies. It's designed to be used as a practice ground for:
- Code optimization techniques
- Performance profiling
- Algorithm improvement
- Best practices implementation
The main.py file contains numerous performance issues including:
- Nested loops where single loops would suffice - Using O(n²) complexity where O(n) is possible
- Bubble sort implementation - Using O(n²) sorting instead of built-in O(n log n) methods
- Manual duplicate removal - O(n²) approach instead of using sets
- Inefficient prime checking - Checking all numbers up to n instead of √n
- String concatenation in loops - Creating new string objects repeatedly
- Redundant list operations - Multiple unnecessary copies and iterations
- Poor memory usage - Storing unnecessary intermediate results
- Recalculating random seeds - Unnecessary function calls in loops
- Recomputing sums - Calculating the same values multiple times
- Redundant sorting - Sorting already sorted data
- Inefficient modulo operations - Using subtraction loops instead of modulo operator
- Unnecessary variable resets - Resetting counters inside loops
- Inefficient condition checking - Complex nested conditions for simple operations
- Missing built-in optimizations - Reimplementing functionality that Python provides efficiently
python main.pyThe program will process a list of 1000 random numbers and perform various operations, displaying timing information to help measure performance improvements.
This code provides excellent opportunities to practice:
- Algorithmic optimization - Replace O(n²) algorithms with O(n) or O(n log n) alternatives
- Built-in usage - Utilize Python's optimized built-in functions and data structures
- Memory optimization - Reduce unnecessary object creation and copying
- Code simplification - Remove redundant calculations and operations
With proper optimization, you should be able to achieve:
- 10-100x performance improvements in most operations
- Significant memory usage reduction
- Cleaner, more readable code
- Better algorithmic complexity
Try to optimize this code while maintaining the same functionality. See how much you can improve the execution time and memory usage!
This repository is set up with Claude API integration for automated optimization responses:
To enable Claude responses, you need to add your Anthropic API key:
- Go to Repository Settings > Secrets and variables > Actions
- Add a new repository secret named
ANTHROPIC_API_KEY - Set the value to your Anthropic API key
- Go to the Issues tab
- Create a new issue describing the optimization you want
- Include
@claudeanywhere in your issue description - Claude will automatically respond with suggestions and optimized code
- Clone this repository locally
- Use Claude Code CLI to work on optimizations
- Submit pull requests with improvements
Title: Optimize bubble sort algorithm
Description:
@claude Please optimize the bubble sort implementation in the `slow_number_processor()` function.
The current implementation is O(n²) and could be improved to O(n log n) using built-in sorting.
Expected improvements:
- Better time complexity
- Cleaner code
- Maintain same functionality
This project is for educational purposes. Feel free to use it for learning and practice.