summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-29 11:06:03 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-29 11:06:03 -0800
commitf38688c8b05c9df9115b49866c86e273bbb3e160 (patch)
treeb5ce468a8273128dfb753f64e2f7944884fabf47 /src/test/java
parent42db035b1099267db8ad4c7f39e3991ff4aad697 (diff)
downloadjava-language-server-f38688c8b05c9df9115b49866c86e273bbb3e160.zip
Benchmark string search approaches
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/javacs/StringSearchBenchmark.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/java/org/javacs/StringSearchBenchmark.java b/src/test/java/org/javacs/StringSearchBenchmark.java
new file mode 100644
index 0000000..015dfdd
--- /dev/null
+++ b/src/test/java/org/javacs/StringSearchBenchmark.java
@@ -0,0 +1,28 @@
+package org.javacs;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.*;
+
+// TODO this is coloring badly
+@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
+@Fork(1)
+public class StringSearchBenchmark {
+ private static final Path largeFile = Paths.get(FindResource.uri("/org/javacs/example/LargeFile.java"));
+ // "removeMethodBodies" appears late in the file, so stopping early will not be very effective
+ private static final String query = "removeMethodBodies";
+
+ @Benchmark
+ public void regex() {
+ var found = Parser.containsWordMatching(largeFile, query);
+ assert found;
+ }
+
+ @Benchmark
+ public void boyerMoore() {
+ var found = Parser.containsText(largeFile, query);
+ assert found;
+ }
+}