Benjamin Maurer (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f1862a...
) *commented* on HHH-14137 (
https://hibernate.atlassian.net/browse/HHH-14137?atlOrigin=eyJpIjoiZWUwOT...
)
Re: Empty String Check Performance Improvement (
https://hibernate.atlassian.net/browse/HHH-14137?atlOrigin=eyJpIjoiZWUwOT...
)
I was a bit skeptical at first, especially bc. of the rational (disseminating equals
method), since HotSpot actually has an intrinsic for String.equals, but my own benchmarks
confirm these results.
I tried Oracle Java 8 on Ubuntu WSL (Win 10) and AdoptOpenJdk 11 on Win 10. I also added
one test case “nullAndPreEquals” which is equal to
org.springframework.util.StringUtils.isEmpty (namely (str == null ||
"".equals(str)) ` ):
Oracle Java 8 (on WSL):
Benchmark (strParams) Mode Cnt Score Error Units
EmptyStringEquals.equalsPost avgt 20 4.193 ± 0.095 ns/op
EmptyStringEquals.equalsPost nonEmptyString avgt 20 3.255 ± 0.034 ns/op
EmptyStringEquals.nonNullAndIsEmpty avgt 20 2.823 ± 0.176 ns/op
EmptyStringEquals.nonNullAndIsEmpty nonEmptyString avgt 20 2.690 ± 0.128 ns/op
EmptyStringEquals.nullAndPreEquals avgt 20 3.886 ± 0.063 ns/op
EmptyStringEquals.nullAndPreEquals nonEmptyString avgt 20 3.260 ± 0.041 ns/op
EmptyStringEquals.preEquals avgt 20 3.874 ± 0.077 ns/op
EmptyStringEquals.preEquals nonEmptyString avgt 20 3.287 ± 0.060 ns/op
AdoptOpenJdk 11 (HotSpot) (on Windows 10):
Benchmark (strParams) Mode Cnt Score Error Units
EmptyStringEquals.equalsPost avgt 20 4,837 ± 0,076 ns/op
EmptyStringEquals.equalsPost nonEmptyString avgt 20 3,880 ± 0,069 ns/op
EmptyStringEquals.nonNullAndIsEmpty avgt 20 3,020 ± 0,048 ns/op
EmptyStringEquals.nonNullAndIsEmpty nonEmptyString avgt 20 3,202 ± 0,095 ns/op
EmptyStringEquals.nullAndPreEquals avgt 20 4,813 ± 0,120 ns/op
EmptyStringEquals.nullAndPreEquals nonEmptyString avgt 20 3,988 ± 0,197 ns/op
EmptyStringEquals.preEquals avgt 20 4,828 ± 0,093 ns/op
EmptyStringEquals.preEquals nonEmptyString avgt 20 3,949 ± 0,072 ns/op
(
https://hibernate.atlassian.net/browse/HHH-14137#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-14137#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:8f92423 )