21 * questions.
22 */
23 package org.openjdk.bench.java.lang;
24
25 import org.openjdk.jmh.annotations.*;
26 import java.util.concurrent.TimeUnit;
27
28 /*
29 * This benchmark naively explores String::equals performance
30 */
31 @BenchmarkMode(Mode.AverageTime)
32 @OutputTimeUnit(TimeUnit.NANOSECONDS)
33 @State(Scope.Thread)
34 @Warmup(iterations = 5, time = 1)
35 @Measurement(iterations = 5, time = 1)
36 @Fork(value = 3)
37 public class StringEquals {
38
39 public String test = new String("0123456789");
40 public String test2 = new String("tgntogjnrognagronagroangroarngorngaorng");
41 public String test3 = new String(test); // equal to test, but not same
42 public String test4 = new String("0123\u01FF");
43 public String test5 = new String(test4); // equal to test4, but not same
44 public String test6 = new String("0123456780");
45 public String test7 = new String("0123\u01FE");
46
47 @Benchmark
48 public boolean different() {
49 return test.equals(test2);
50 }
51
52 @Benchmark
53 public boolean equal() {
54 return test.equals(test3);
55 }
56
57 @Benchmark
58 public boolean almostEqual() {
59 return test.equals(test6);
60 }
61
62 @Benchmark
|
21 * questions.
22 */
23 package org.openjdk.bench.java.lang;
24
25 import org.openjdk.jmh.annotations.*;
26 import java.util.concurrent.TimeUnit;
27
28 /*
29 * This benchmark naively explores String::equals performance
30 */
31 @BenchmarkMode(Mode.AverageTime)
32 @OutputTimeUnit(TimeUnit.NANOSECONDS)
33 @State(Scope.Thread)
34 @Warmup(iterations = 5, time = 1)
35 @Measurement(iterations = 5, time = 1)
36 @Fork(value = 3)
37 public class StringEquals {
38
39 public String test = new String("0123456789");
40 public String test2 = new String("tgntogjnrognagronagroangroarngorngaorng");
41 @SuppressWarnings("initialization")
42 public String test3 = new String(test); // equal to test, but not same
43 public String test4 = new String("0123\u01FF");
44 @SuppressWarnings("initialization")
45 public String test5 = new String(test4); // equal to test4, but not same
46 public String test6 = new String("0123456780");
47 public String test7 = new String("0123\u01FE");
48
49 @Benchmark
50 public boolean different() {
51 return test.equals(test2);
52 }
53
54 @Benchmark
55 public boolean equal() {
56 return test.equals(test3);
57 }
58
59 @Benchmark
60 public boolean almostEqual() {
61 return test.equals(test6);
62 }
63
64 @Benchmark
|