-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Optimize assertArrayEquals() #924
Conversation
@junit-team/junit-committers could one of you review? Thanks. |
/** | ||
* Gets the length of the array of actual values. | ||
*/ | ||
int getActualArrayLength(); |
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.
How about using java.lang.reflect.Array::getLength()
for this method and getExpectedArrayLength
? Is it expensive as well?
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.
Ok, I see it was used before...
One of my coworkers wrote some Caliper microbenchmarks for |
return; | ||
} | ||
|
||
assertElementsEqual(messagePrefix, comparisonHelper); |
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.
What do you think about changing this code to
if (!arraysTriviallyEqual(messagePrefix, expecteds, actuals)) {
assertElementsEqual(messagePrefix, comparisonHelper);
}
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.
Done
Don't merge this yet; I have some updated stats from the benchmarks |
I reran the benchmarks. See my comment in #918 |
These changes speed up comparisons of one dimensional arrays of primatives between 98.0% and 99.8% and speed up comparisons of multi-dimensional arrays between 81.4% and 82.8%
a485707
to
75d80f7
Compare
This change avoids using reflection when calling assertArrayEquals() for all primitive types except float and double. It does increase the amount of duplication in the code, but I've tried to keep the duplicates trivial and to a minimum.