New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmark for JUnitTestCaseSorter::uniqueByTestFile #1177
Conversation
… into pr/2020-03/test-timings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nitpicks looks good to me otherwise
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
I would also love us to add a benchmark to profile the mutations -> mutant process, but I don't think it should hold this PR either |
Co-Authored-By: Théo FIDRY <theo.fidry@gmail.com>
I'd love to test it with the new benchmarks, but this isn't particularly easy because we test only so much mutations, not the whole range. I'll see to it anyway a bit later. |
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting PR. I can't say I understood every single line here (which makes me think it will probably be hard to support this code for average contributor without digging into the theory), but it seems like a very smart improvemnt.
- Does Psalm have many mutations with >15 tests that cover the mutated line?
- Is this diagram for Psalm?
- What is the performance win in % for Psalm?
… into pr/2020-03/test-timings
Third point is the major point for me. Even if local benchmarks show improvement, global improvement might be below the noise threshold. I'd like to see them, and to show them, but it appears to be hard for one reason or another. |
* Tweak JUnitTestCaseSorter * Update comment * Update return type
tests/phpunit/TestFramework/Coverage/JUnit/JUnitTestCaseSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/TestLocationBucketSorterTest.php
Outdated
Show resolved
Hide resolved
tests/phpunit/TestFramework/Coverage/JUnit/TestLocationBucketSorterTest.php
Outdated
Show resolved
Hide resolved
…Test.php Co-Authored-By: Théo FIDRY <theo.fidry@gmail.com>
… into pr/2020-03/test-timings
This PR:
isset()
required for PHP 7.4?Looking just at the Big O notation for the bucket sort, it seems to be more effective in general, but for smaller number of items and/or for larger number of buckets Quicksort is more effective, again, looking at the notation only.
Here's a Big O graph for 23 buckets:
Blue is for quicksort. Orange is for bucket sort.
For 25 buckets we're aiming the sort becomes theoretically more effective after 15 elements. Considering that we don't do the second stage of intra-bucket sorting, this effectiveness boundary might be closer for us, yet still far.
If we consider the distribution of overly tested mutations, we can see that our bucket sort will be applied in roughly 40% of cases in case of Psalm.
Bucket selection algorithm
Since effectiveness of the algorithm is in direct relationship with the number of buckets, and since our data is effectively skewed towards a specific mode at around 1/3 of a second, it does not help if we use a fixed number of buckets.
Instead we gradually lower precision of our timings starting with 8th of a second, later lowering it to 4 seconds. Also we pre-sort bucket array for the first second worth of buckets. By using calculated buckets we try to avoid looping around bucket numbers.
Example of a bucket distribution
Further optimization begs the following questions: