⚡️ Speed up method TestResults.timing_coefficient_of_variation by 338% in PR #1949 (cf-1082-benchmark-noise-floor)#1955
Merged
claude[bot] merged 2 commits intocf-1082-benchmark-noise-floorfrom Apr 1, 2026
Conversation
The hot-path `timing_coefficient_of_variation()` was replaced with Welford's single-pass algorithm to compute sample standard deviation and mean in one traversal instead of calling `statistics.mean()` and `statistics.stdev()` separately (which each iterate the list). Line profiler shows the original's `statistics.stdev()` consumed 47.6% of function runtime; the new `_compute_sample_cv` cuts that to 16.2% by eliminating redundant passes and reducing overhead from Python's general-purpose statistics module. Overall runtime drops 77% (245 µs → 55.8 µs), a key speedup in `process_single_candidate` where this method gates candidate evaluation.
Contributor
|
Claude finished @codeflash-ai[bot]'s task in 5m 8s —— View job PR Review SummaryPrek Checks✅ Passes. No issues introduced by this PR. (14 pre-existing mypy errors in Code ReviewCorrectness: The Welford single-pass algorithm is implemented correctly:
Style fix applied: No bugs, security issues, or breaking API changes found. Duplicate DetectionNo duplicates detected. Other open codeflash-ai PRs
Last updated: 2026-04-01T17:57Z |
fc9a6b2
into
cf-1082-benchmark-noise-floor
24 of 26 checks passed
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
⚡️ This pull request contains optimizations for PR #1949
If you approve this dependent PR, these changes will be merged into the original PR branch
cf-1082-benchmark-noise-floor.📄 338% (3.38x) speedup for
TestResults.timing_coefficient_of_variationincodeflash/models/models.py⏱️ Runtime :
245 microseconds→55.8 microseconds(best of250runs)📝 Explanation and details
The hot-path
timing_coefficient_of_variation()was replaced with Welford's single-pass algorithm to compute sample standard deviation and mean in one traversal instead of callingstatistics.mean()andstatistics.stdev()separately (which each iterate the list). Line profiler shows the original'sstatistics.stdev()consumed 47.6% of function runtime; the new_compute_sample_cvcuts that to 16.2% by eliminating redundant passes and reducing overhead from Python's general-purpose statistics module. Overall runtime drops 77% (245 µs → 55.8 µs), a key speedup inprocess_single_candidatewhere this method gates candidate evaluation.✅ Correctness verification report:
⚙️ Click to see Existing Unit Tests
test_critic.py::test_timing_coefficient_of_variationtest_critic.py::test_timing_cv_multi_test_case🌀 Click to see Generated Regression Tests
To edit these changes
git checkout codeflash/optimize-pr1949-2026-04-01T17.51.09and push.