Skip to content

Commit 13cc20e

Browse files
authored
Merge pull request #42 from nanasess/performance-tests
docs: add performance benchmarking and GitHub Actions integration details to README
2 parents 8faa165 + 3b75f7b commit 13cc20e

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,89 @@ The `bcround()` function supports PHP 8.4's `RoundingMode` enum through a polyfi
9292

9393
This polyfill uses [phpseclib](https://github.com/phpseclib/phpseclib)'s BigInteger class for arbitrary precision arithmetic, providing reliable performance for applications that cannot use the native bcmath extension.
9494

95+
### Performance Benchmarking
96+
97+
This project includes a comprehensive benchmarking tool to compare the performance of the polyfill against native bcmath functions.
98+
99+
#### Local Benchmark Execution
100+
101+
```bash
102+
# Run benchmark with default settings (10,000 iterations)
103+
composer benchmark
104+
# or
105+
php benchmarks/run-benchmarks.php
106+
107+
# Export results in different formats
108+
php benchmarks/run-benchmarks.php -f json -o results.json
109+
php benchmarks/run-benchmarks.php -f csv -o results.csv
110+
php benchmarks/run-benchmarks.php -f markdown -o BENCHMARK.md
111+
112+
# Show help
113+
php benchmarks/run-benchmarks.php --help
114+
```
115+
116+
#### Benchmark Configuration
117+
118+
The benchmark tests include:
119+
- **Basic Operations**: Addition, subtraction, multiplication, division with various number sizes
120+
- **Advanced Operations**: Power, square root, modulo operations
121+
- **Large Numbers**: Operations with 100, 500, and 1000 digit numbers
122+
- **High Precision**: Operations with scale values of 20, 50, and 100
123+
124+
#### Interpreting Results
125+
126+
Typical performance comparison shows:
127+
- **Basic operations**: Polyfill is ~100-250x slower than native
128+
- **Large numbers**: Performance gap increases with number size (up to ~800x slower)
129+
- **Square root**: Interestingly, polyfill can be faster for high-precision operations
130+
131+
Example output:
132+
```
133+
BCMath Performance Benchmark
134+
========================================
135+
Iterations per test: 10000
136+
Native BCMath: Available
137+
138+
Basic Operations
139+
----------------
140+
Small numbers (10 digits):
141+
bcadd | Native: 1.5ms | Polyfill: 230ms | Ratio: 150x slower
142+
...
143+
144+
Summary
145+
========================================
146+
Average performance ratio: 26x
147+
Polyfill is on average 26x slower than native
148+
```
149+
150+
### GitHub Actions Integration
151+
152+
The project includes automated benchmarking workflows:
153+
154+
#### 1. PR Benchmarks (`/benchmark` command)
155+
Comment `/benchmark` on any PR to run performance tests:
156+
- Automatically triggered on PR updates to relevant files
157+
- Quick mode (1,000 iterations) for fast feedback
158+
- Results posted as PR comment
159+
160+
#### 2. Merge Benchmarks
161+
Automatically runs when PRs are merged to main:
162+
- Full benchmark (10,000 iterations)
163+
- Results posted to the merged PR for reference
164+
165+
#### 3. Manual Benchmarks
166+
Trigger via GitHub Actions UI:
167+
- Customizable iteration count
168+
- Multi-PHP version testing (8.1, 8.2, 8.3, 8.4)
169+
- Results saved as artifacts
170+
171+
### Performance Considerations
172+
173+
While the polyfill is significantly slower than native bcmath:
174+
- It provides full functionality when bcmath extension is unavailable
175+
- Performance is adequate for most applications not requiring intensive calculations
176+
- Consider using native bcmath for performance-critical applications
177+
95178
## ⚠️ Known Limitations
96179

97180
### Extension Detection

0 commit comments

Comments
 (0)