Commit fda19ea
authored
Optimize discover_parameters_unittest
The optimized code achieves a 252% speedup through two key optimizations:
**1. Early Exit for No Underscores**: Added a check `if '_' not in function_name:` that immediately returns `False` for strings without underscores. This avoids unnecessary splitting operations for simple function names, providing significant speedups (51-69% faster) for cases like single words or empty strings.
**2. Right-Split Optimization**: Replaced `split("_")` with `rsplit("_", 1)` which only splits from the right once, creating exactly 2 parts instead of potentially hundreds. This dramatically reduces memory allocation and processing time, especially for long function names with many underscores.
**Performance Impact by Test Type**:
- **Simple cases** (no underscores): 51-69% faster due to early exit
- **Valid numeric suffixes**: 21-50% faster from efficient rsplit
- **Large-scale tests**: 660-3584% faster - the rsplit optimization shines here, avoiding expensive operations on strings with hundreds of parts
- **Edge cases with non-numeric suffixes**: Slight 2-13% slowdown due to the additional underscore check, but this is minimal compared to the gains
The optimizations preserve exact functionality while being most effective for complex function names with many parts, which are common in parameterized test scenarios.1 parent ce72cfd commit fda19ea
1 file changed
+6
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | | - | |
527 | | - | |
528 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
529 | 532 | | |
530 | 533 | | |
531 | 534 | | |
| |||
0 commit comments