Why is Arrays.equals(char[], char[]) 8 times faster than all the other versions?

前端 未结 3 496
失恋的感觉
失恋的感觉 2021-02-02 10:31

Short Story

Based on my tests with a few different Oracle and OpenJDK implementations, it seems that Arrays.equals(char[], char[]) is somehow about 8 times fas

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 11:03

    I might go out on a limb when suggesting that this is the answer, but according to http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/9d15b81d5d1b/src/share/vm/classfile/vmSymbols.hpp#l756, the Arrays#equals(char[], char[]) method is implemented as an intrinsic.

    Most likely because it is highly performance critical in all string comparisons. <- This was wrong, at least. Surprisingly, String does not use Arrays.equals for the comparison. But regardless of why it is an intrinsic, this may still be the reason for the performance difference.

提交回复
热议问题