8302163: Speed up various String comparison methods with ArraysSupport.mismatch

Reviewed-by: stsypanov, rriggs, alanb
This commit is contained in:
Claes Redestad 2023-02-15 21:52:41 +00:00
parent 50dcc2aec5
commit 861e302011
5 changed files with 127 additions and 64 deletions

View file

@ -49,17 +49,9 @@ public class StringOther {
private String testString;
private Random rnd;
private String str1, str2, str3, str4;
private String str1UP;
@Setup
public void setup() {
testString = "Idealism is what precedes experience; cynicism is what follows.";
str1 = "vm-guld vm-guld vm-guld";
str1UP = str1.toUpperCase(Locale.ROOT);
str2 = "vm-guld vm-guld vm-guldx";
str3 = "vm-guld vm-guld vm-guldx";
str4 = "adadaskasdjierudks";
rnd = new Random();
}
@ -70,15 +62,6 @@ public class StringOther {
}
}
@Benchmark
public int compareTo() {
int total = 0;
total += str1.compareTo(str2);
total += str2.compareTo(str3);
total += str3.compareTo(str4);
return total;
}
/**
* Creates (hopefully) unique Strings and internizes them, creating a zillion forgettable strings in the JVMs string
* pool.
@ -94,10 +77,4 @@ public class StringOther {
return String.valueOf(rnd.nextInt()).intern();
}
@Benchmark
public void regionMatchesLatin1(Blackhole bh) {
bh.consume(str1.regionMatches(true, 0, str2, 0, str1.length()));
bh.consume(str2.regionMatches(true, 16, str1UP, 0, 8));
bh.consume(str3.regionMatches(true, 6, str4, 1, 2));
}
}