-
Notifications
You must be signed in to change notification settings - Fork 366
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
Improve calculating symmetric difference #1944
Merged
Merged
Conversation
This file contains 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
Calculating symmetric difference is common in the code, while s1.Difference(s2).Union(s2.Difference(s1)) is a little complicated, error-prone, and always builds several unnecessary intermediate sets. This patch adds an util function SymmetricDifference to improve it. The benchmark impact is as below when calculating symmetric difference of two sets each of which contains 2000 items: name old time/op new time/op delta SymmetricDifference-48 1.50ms ± 1% 0.87ms ± 3% -42.10% (p=0.008 n=5+5) name old alloc/op new alloc/op delta SymmetricDifference-48 342kB ± 0% 171kB ± 0% -49.99% (p=0.008 n=5+5) name old allocs/op new allocs/op delta SymmetricDifference-48 132 ± 0% 61 ± 0% -53.79% (p=0.029 n=4+4)
Codecov Report
@@ Coverage Diff @@
## main #1944 +/- ##
===========================================
+ Coverage 52.04% 62.41% +10.36%
===========================================
Files 204 204
Lines 17527 17533 +6
===========================================
+ Hits 9122 10943 +1821
+ Misses 7203 5423 -1780
+ Partials 1202 1167 -35
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/test-all |
/test-networkpolicy |
antoninbas
approved these changes
Mar 9, 2021
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.
LGTM
tnqn
added a commit
to tnqn/antrea
that referenced
this pull request
Mar 17, 2021
Calculating symmetric difference is common in the code, while s1.Difference(s2).Union(s2.Difference(s1)) is a little complicated, error-prone, and always builds several unnecessary intermediate sets. This patch adds an util function SymmetricDifference to improve it. The benchmark impact is as below when calculating symmetric difference of two sets each of which contains 2000 items: name old time/op new time/op delta SymmetricDifference-48 1.50ms ± 1% 0.87ms ± 3% -42.10% (p=0.008 n=5+5) name old alloc/op new alloc/op delta SymmetricDifference-48 342kB ± 0% 171kB ± 0% -49.99% (p=0.008 n=5+5) name old allocs/op new allocs/op delta SymmetricDifference-48 132 ± 0% 61 ± 0% -53.79% (p=0.029 n=4+4)
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.
Calculating symmetric difference is common in the code, while
s1.Difference(s2).Union(s2.Difference(s1)) is a little complicated,
error-prone, and always builds several unnecessary intermediate sets.
This patch adds an util function SymmetricDifference to improve it. The
benchmark impact is as below when calculating symmetric difference of
two sets each of which contains 2000 items: