Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

kcooney
Copy link
Member

@kcooney kcooney commented May 31, 2014

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.

@kcooney
Copy link
Member Author

kcooney commented Jun 3, 2014

@junit-team/junit-committers could one of you review? Thanks.

/**
* Gets the length of the array of actual values.
*/
int getActualArrayLength();
Copy link
Member

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?

Copy link
Member

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...

@kcooney kcooney changed the title Optimize assertArrayEquals() for primative non-floating point types. Optimize assertArrayEquals() Jun 3, 2014
@kcooney
Copy link
Member Author

kcooney commented Jul 8, 2014

One of my coworkers wrote some Caliper microbenchmarks for assertArrayEquals() and I ran them using the JUnit 4.10 implementation as a baseline. I put the results in the commit description after doing a rebase and squashing commits.

return;
}

assertElementsEqual(messagePrefix, comparisonHelper);
Copy link
Contributor

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);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kcooney
Copy link
Member Author

kcooney commented Jul 25, 2014

Don't merge this yet; I have some updated stats from the benchmarks

@kcooney
Copy link
Member Author

kcooney commented Jul 29, 2014

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%
@kcooney kcooney force-pushed the optimize-array-equals branch from a485707 to 75d80f7 Compare September 9, 2014 16:17
@marcphilipp
Copy link
Member

@kcooney Since #918 is merged and released, can we close this pull request?

@kcooney kcooney closed this Sep 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants