Performance Comparison between String compareTo and String equals

String.equals is used to compare strings for equality, whereas compareTo is used for a lexicographic comparison (knowing which is greater, for the purpose of sorting).
However, I was wondering under what situations compareTo might be faster than equals for the purpose of an equality check. Following are some observations. The first high figure would be due to the Hotspot native compilation.

JVM: Sun 1.4.2 (Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
Source code of test  html Source code of test
TeststEQUALS COMPARETO Analysis
1) equal substrings of a string ABCDABCD43 ms
15 ms
15 ms
7 ms
6 ms
6 ms

most likely due to extra typecast. equals's length check is also redundant here
2) content different, length same ABCDEFGDEFGHIJ8 ms
7 ms
7 ms
4 ms
4 ms
4 ms

probably due to typecast and ref check in equals
3) content overlaps, length diff ABCDEFGABCDEFGH5 ms
4 ms
4 ms

9 ms
9 ms
11 ms
equals has a length check, compareTo doesnt
4) content same ABCDEFGABCDEFG23 ms
22 ms
23 ms
9 ms
8 ms
9 ms

most likely because equals does extra typecast and ref check and length check
5) content diff, length diff ABCDEFGabcedfgh5 ms
4 ms
4 ms
4 ms
5 ms
8 ms
equals has a length check
6) content diff at first byte, length same ABCDEFGaBCEDFG8 ms
9 ms
7 ms
4 ms
5 ms
4 ms

equals has a countdown loop thus slower
7) same reference ABCDEFGABCDEFG4 ms
4 ms
5 ms

11 ms
10 ms
11 ms
equals does a refernece check first

Notes from source code of jdk 1.4.2.:

equals():
compareTo():

Other possible test:

Please give feedback, analysis, other tests to me at rahul_kumar@yahoo.com. Thanks.

Rahul Kumar, 2003-11-12