Skip to content

Yang92047111/IO-Performance-Comparison

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ I/O Performance Comparison: Python vs Go vs Kotlin

License: MIT Python Go Kotlin

A comprehensive benchmarking suite that compares file I/O performance across Python, Go, and Kotlin implementations. This project provides detailed performance analysis with statistical rigor and beautiful visualizations.

✨ Features

  • πŸ”„ Multi-language benchmarking: Tests Python, Go, and Kotlin I/O performance
  • πŸ“Š Multiple file sizes: Tests with 1MB, 10MB, 50MB, and 100MB files
  • πŸ“ˆ Statistical analysis: Multiple iterations with mean, median, min, max, and standard deviation
  • πŸ“‰ Visual comparisons: Generates performance charts and graphs
  • ⚑ Throughput metrics: Measures MB/s for read and write operations
  • πŸ€– Automated execution: Single command runs all benchmarks
  • πŸ”§ Cross-platform: Works on macOS, Linux, and Windows

πŸ“ Project Structure

β”œβ”€β”€ benchmark_runner.py      # 🎯 Main benchmark orchestrator
β”œβ”€β”€ quick_test.py            # πŸ§ͺ Quick implementation tester
β”œβ”€β”€ test_setup.py           # βš™οΈ Setup verification script
β”œβ”€β”€ python/
β”‚   β”œβ”€β”€ io_benchmark.py     # 🐍 Python I/O implementation
β”‚   └── io_test.py          # 🐍 Python test runner
β”œβ”€β”€ golang/
β”‚   β”œβ”€β”€ main.go             # 🐹 Go I/O implementation
β”‚   └── go.mod              # 🐹 Go module definition
β”œβ”€β”€ kotlin/
β”‚   └── app/
β”‚       └── src/main/kotlin/org/example/
β”‚           └── App.kt      # 🎯 Kotlin I/O implementation
β”œβ”€β”€ data/                   # πŸ“‚ Test files (auto-generated)
β”œβ”€β”€ results/                # πŸ“Š Benchmark results (auto-generated)
β”œβ”€β”€ Makefile               # πŸ”¨ Build and run commands
β”œβ”€β”€ requirements.txt       # πŸ“¦ Python dependencies
└── .gitignore             # 🚫 Git ignore rules

πŸš€ Quick Start

Prerequisites

  • 🐍 Python 3.7+
  • 🐹 Go 1.19+
  • β˜• Java 11+ (for Kotlin)
  • πŸ”¨ Make (build automation)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/io-performance-comparison.git
    cd io-performance-comparison
  2. Install dependencies (creates Python virtual environment automatically)

    make install-deps

πŸ’‘ Note: On macOS/Linux, this automatically creates a Python virtual environment to avoid conflicts with system Python packages.

πŸƒβ€β™‚οΈ Running Benchmarks

Run the complete benchmark suite:

make benchmark

Test individual implementations:

make test-individual

Quick verification test:

python3 quick_test.py

Run specific language tests:

make run-python    # 🐍 Python only
make run-go        # 🐹 Go only
make run-kotlin    # Kotlin only

Benchmark Details

Test Operations

  1. Write Test: Copy a test file using 8KB buffer chunks
  2. Read Test: Read the copied file using 8KB buffer chunks

File Sizes Tested

  • 1 MB
  • 10 MB
  • 50 MB
  • 100 MB

Metrics Collected

  • Execution Time: Time taken for read/write operations
  • Throughput: MB/s for each operation
  • Statistical Analysis: Mean, median, min, max, standard deviation
  • Relative Performance: Performance ratios compared to Go baseline

πŸ“Š Sample Results

Here's what you can expect from the benchmark results:

Language File Size Read (MB/s) Write (MB/s)
Go 100MB 3,856 815
Kotlin 100MB 4,054 802
Python 100MB 4,054 805

Results may vary based on hardware and system configuration

πŸ“ Output Files

After running benchmarks, check the results/ directory:

  • πŸ“„ benchmark_results.json: Raw benchmark data with all iterations
  • πŸ“Š benchmark_summary.csv: Tabulated results with statistics
  • πŸ“ˆ io_performance_comparison.png: Performance visualization charts

πŸ”§ Implementation Details

🐍 Python Implementation

  • Uses built-in open() with binary mode
  • 8KB buffer size for chunked I/O
  • Context managers for proper file handling
  • JSON output for benchmark results

🐹 Go Implementation

  • Uses os.Open() and os.Create()
  • 8KB byte slice buffer
  • Proper error handling and resource cleanup
  • Structured JSON output with custom types

🎯 Kotlin Implementation

  • Uses FileInputStream/FileOutputStream
  • 8KB ByteArray buffer
  • Automatic resource management with use{}
  • Gson for JSON serialization

Performance Expectations

Typical performance characteristics:

  • Go: Generally fastest, especially for large files
  • Kotlin: Close to Go performance, benefits from JVM optimizations
  • Python: Slower for pure I/O, but difference narrows with larger files

Results vary based on:

  • Hardware (SSD vs HDD, CPU, RAM)
  • Operating system
  • File system type
  • System load

Customization

Modify Test Parameters

Edit benchmark_runner.py:

self.test_file_sizes = [1, 10, 50, 100]  # File sizes in MB
self.iterations = 3                       # Number of test runs

Change Buffer Size

Update buffer size in each implementation:

  • Python: chunk = f_in.read(8192)
  • Go: buf := make([]byte, 8192)
  • Kotlin: val buffer = ByteArray(8192)

Troubleshooting

Common Issues

  1. Missing dependencies: Run make install-deps
  2. Permission errors: Ensure write access to project directory
  3. Out of disk space: Large test files require sufficient free space
  4. Java/Kotlin build errors: Verify Java 11+ is installed

Clean Up

Remove generated files:

make clean

Remove everything including virtual environment:

make clean-all

🀝 Contributing

We welcome contributions! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. ✨ Add your improvements
    • New language implementations
    • Performance optimizations
    • Better visualizations
    • Bug fixes
  4. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  5. πŸš€ Push to the branch (git push origin feature/amazing-feature)
  6. πŸ”„ Submit a pull request

Ideas for Contributions

  • πŸ¦€ Rust implementation
  • πŸ”· C# implementation
  • β˜• Java implementation
  • πŸ“Š More visualization options
  • πŸ”§ Different I/O patterns (async, memory-mapped, etc.)
  • πŸ§ͺ Additional test scenarios

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

  • Thanks to all contributors who help improve this benchmark suite
  • Inspired by the need for fair, comprehensive I/O performance comparisons
  • Built with ❀️ for the developer community

⭐ If this project helped you, please give it a star!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published