This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-469
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-469 by this push:
new c6a7696 WIP.
c6a7696 is described below
commit c6a76968e94c4edc4f8895cb86980a65805dce4a
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Dec 22 19:54:07 2021 +0300
WIP.
---
nlpcraft/pom.xml | 14 +++
.../internal/nlp/benchmark/NCBenchmarkAdapter.java | 101 +++++++++++++++++++++
.../opennlp/NCOpenNlpTokenParserBenchmark.java | 61 +++++++++++++
.../parser/opennlp/NCOpenNlpTokenParserSpec.scala | 2 +-
pom.xml | 1 +
5 files changed, 178 insertions(+), 1 deletion(-)
diff --git a/nlpcraft/pom.xml b/nlpcraft/pom.xml
index 1f17ff8..e181e50 100644
--- a/nlpcraft/pom.xml
+++ b/nlpcraft/pom.xml
@@ -136,6 +136,20 @@
<version>${scalatest.ver}</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.openjdk.jmh</groupId>
+ <artifactId>jmh-core</artifactId>
+ <version>${jmh.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openjdk.jmh</groupId>
+ <artifactId>jmh-generator-annprocess</artifactId>
+ <version>${jmh.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java
b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java
new file mode 100644
index 0000000..e31466c
--- /dev/null
+++
b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/NCBenchmarkAdapter.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.
+ */
+
+package org.apache.nlpcraft.internal.nlp.benchmark;
+
+import org.apache.nlpcraft.NCRequest;
+import org.junit.jupiter.api.Test;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Benchmark)
+@Fork(value = 1, jvmArgs = {"-Xms2G", "-Xmx2G"})
+@Warmup(iterations = 5, time = 10)
+@Measurement(iterations = 5, time = 5)
+public class NCBenchmarkAdapter {
+ @State(Scope.Thread)
+ public static class NCBenchmarkAdapterState {
+ public NCRequest request = new NCRequest() {
+ private final String TXT =
+ "I am developing an integrated Benchmarking into an
application, I want to use JMH as my framework.";
+ private final String NORM = TXT.toLowerCase();
+
+ @Override
+ public String getUserId () {
+ return null;
+ }
+
+ @Override
+ public String getRequestId () {
+ return null;
+ }
+
+ @Override
+ public String getNormalizedText () {
+ return NORM;
+ }
+
+ @Override
+ public String getOriginalText () {
+ return TXT;
+ }
+
+ @Override
+ public long getReceiveTimestamp () {
+ return 0;
+ }
+
+ @Override
+ public String getUserAgent () {
+ return null;
+ }
+
+ @Override
+ public Map<String, Object> getRequestData () {
+ return null;
+ }
+ };
+ }
+
+ /**
+ *
+ * @param args
+ * @throws RunnerException
+ */
+ @Test
+ public void benchmark() throws RunnerException {
+ new Runner(
+ new OptionsBuilder().
+ include(this.getClass().getSimpleName()).
+ build()
+ ).run();
+ }
+}
diff --git
a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/token/parser/opennlp/NCOpenNlpTokenParserBenchmark.java
b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/token/parser/opennlp/NCOpenNlpTokenParserBenchmark.java
new file mode 100644
index 0000000..b7501eb
--- /dev/null
+++
b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/benchmark/token/parser/opennlp/NCOpenNlpTokenParserBenchmark.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * https://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.
+ */
+
+package org.apache.nlpcraft.internal.nlp.benchmark.token.parser.opennlp;
+
+import org.apache.nlpcraft.internal.nlp.benchmark.NCBenchmarkAdapter;
+import
org.apache.nlpcraft.internal.nlp.token.parser.opennlp.NCEnStopWordsFinder;
+import
org.apache.nlpcraft.internal.nlp.token.parser.opennlp.NCOpenNlpTokenParser;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.infra.Blackhole;
+
+public class NCOpenNlpTokenParserBenchmark extends NCBenchmarkAdapter {
+ private NCOpenNlpTokenParser prepared;
+
+ @Setup
+ public void setUp() {
+ prepared = prepareParser();
+ }
+
+ @Benchmark
+ public void testInitialize(Blackhole bh) {
+ bh.consume(prepareParser());
+ }
+
+ @Benchmark
+ public void testParse(Blackhole bh,
NCBenchmarkAdapter.NCBenchmarkAdapterState state) {
+ bh.consume(prepared.parse(state.request));
+ }
+
+ /***
+ *
+ * @return
+ */
+ private static NCOpenNlpTokenParser prepareParser() {
+ NCOpenNlpTokenParser p = new NCOpenNlpTokenParser(
+ "opennlp/en-token.bin",
+ "opennlp/en-pos-maxent.bin",
+ "opennlp/en-lemmatizer.dict",
+ new NCEnStopWordsFinder()
+ );
+
+ p.start();
+
+ return p;
+ }
+}
diff --git
a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
index a8fc4fe..88c919c 100644
---
a/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
+++
b/nlpcraft/src/test/java/org/apache/nlpcraft/internal/nlp/token/parser/opennlp/NCOpenNlpTokenParserSpec.scala
@@ -94,7 +94,7 @@ class NCOpenNlpTokenParserSpec:
validate(res)
@Test
- def test(): Unit =
+ def benchmark(): Unit =
test(
"Test requests!",
toks =>
diff --git a/pom.xml b/pom.xml
index 039dc9d..a7a091d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,6 +106,7 @@
<scalatest.ver>3.2.9</scalatest.ver>
<gson.ver>2.8.5</gson.ver>
<apache.opennlp.ver>1.9.4</apache.opennlp.ver>
+ <jmh.version>1.33</jmh.version>
<!-- Force specific encoding on text resources. -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>