String.equalsIgnoreCase(...) optimization

Andrey andrey at tweak.su
Tue Apr 26 22:21:33 UTC 2016


I create simple benchmark (attached). Optimized version more faster:

# JMH 1.12 (released 26 days ago)
# VM version: JDK 1.8.0_91, VM 25.91-b14
...
# Run complete. Total time: 00:04:02

Benchmark                        Mode  Cnt         Score        Error  Units
StringBenchmark.constConst         thrpt   20  37935470,179 ▒ 158354,736  ops/s
StringBenchmark.constConstFast  thrpt   20  70342038,623 ▒ 727831,951  ops/s
StringBenchmark.newNew             thrpt   20  30033885,754 ▒ 374524,932  ops/s
StringBenchmark.newNewFast      thrpt   20  69567918,934 ▒ 196494,474  ops/s
StringBenchmark.varVar                thrpt   20  36102111,956 ▒ 364861,774  ops/s
StringBenchmark.varVarFast         thrpt   20  66743826,698 ▒ 124162,725  ops/s

How I can publish my version equalsIgnoreCase(...) or OpenJDK team check results separately?

26.04.2016, 18:18, "Andrew Haley" <aph at redhat.com>:
>  On 04/26/2016 03:25 PM, Andrey wrote:
>>   May be can create optimized regionMatches(...) for use in equalsIgnoreCase(...)?
>
>  When the HotSpot JVM's just-in-time compiler optimizes this code it
>  inlines all of these tests, realizes that they are constant values,
>  and generates no code for them. All the generated code does is check
>  that the strings have the same coder and are the same length, then it
>  goes into an unrolled loop checking that the characters are the same.
>  If they're different then we have to do some more testing.
>
>  If you want to optimize any library code its a great idea to make some
>  changes and use JMH (http://openjdk.java.net/projects/code-tools/jmh/)
>  to see if your change makes your test run faster.
>
>  Andrew.


More information about the core-libs-dev mailing list