summaryrefslogtreecommitdiff
path: root/BenchmarkFramework/app/src/main/java/art_benchmarks/micro/StringEquals.java
diff options
context:
space:
mode:
Diffstat (limited to 'BenchmarkFramework/app/src/main/java/art_benchmarks/micro/StringEquals.java')
-rw-r--r--BenchmarkFramework/app/src/main/java/art_benchmarks/micro/StringEquals.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/BenchmarkFramework/app/src/main/java/art_benchmarks/micro/StringEquals.java b/BenchmarkFramework/app/src/main/java/art_benchmarks/micro/StringEquals.java
new file mode 100644
index 0000000..012c92c
--- /dev/null
+++ b/BenchmarkFramework/app/src/main/java/art_benchmarks/micro/StringEquals.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2015 Linaro Limited. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/*
+ * Description: Tracks performance of String.equals when working with
+ * cache-limiting amounts of character data. Some prefetch
+ * hint investigations have shown a performance gain here.
+ * Main Focus: Comparison of many, very large (re: L1 cache) strings.
+ * Secondary Focus:
+ *
+ */
+
+/*
+ * TODO: Test various sizes of strings.
+ * TODO: Benchmark other cases, like comparing strings of different
+ * sizes together (probably the most command case), or similar
+ * strings that have a run of equal characters to begin with.
+ */
+
+package art_benchmarks.micro;
+
+import java.lang.StringBuilder;
+import java.util.Random;
+
+public class StringEquals {
+ private static Random rnd = new Random(0);
+ private static final int NUM_Equals = 1024;
+ private static final int STR_Length = 512;
+ private static String[] randomStrings = new String[NUM_Equals];
+ private static Boolean[] equalsResults = new Boolean[NUM_Equals - 1];
+
+ static {
+ generateRandomStrings();
+ }
+
+ private static void generateRandomStrings() {
+ for (int i = 0; i < NUM_Equals; i++) {
+ StringBuilder sb = new StringBuilder();
+ for (int j = 0; j < STR_Length; j++) {
+ sb.append(Character.valueOf((char)(rnd.nextInt(25) + 65)));
+ }
+ randomStrings[i] = sb.toString();
+ }
+ }
+
+ public void timeEquals(int iterations) {
+ for (int i = 0; i < iterations; i++) {
+ for (int j = 0; j < NUM_Equals - 1; j++) {
+ equalsResults[j] = randomStrings[j].equals(randomStrings[j + 1]);
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ StringEquals eq = new StringEquals();
+ long before = System.currentTimeMillis();
+ eq.timeEquals(1500);
+ eq.timeEquals(1500);
+ long after = System.currentTimeMillis();
+ System.out.println("art_benchmarks/micro/StringEquals: " + (after - before));
+ }
+}