This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-mime4j.git

commit 133ac409404895a992c894b1e62a86036cc39082
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Tue Jun 21 10:49:26 2022 +0700

    MIME4J-317 JMH benchmark: DOM fields
---
 benchmark/pom.xml                                  |  10 +-
 .../org/apache/james/mime4j/JMHFieldBench.java     | 114 +++++++++++++++++++++
 .../james/mime4j/JMHLongMultipartReadBench.java    |   2 +-
 3 files changed, 120 insertions(+), 6 deletions(-)

diff --git a/benchmark/pom.xml b/benchmark/pom.xml
index 3995563b..3fd6ee2c 100644
--- a/benchmark/pom.xml
+++ b/benchmark/pom.xml
@@ -35,14 +35,14 @@
 
     <dependencies>
         <dependency>
-        <groupId>org.openjdk.jmh</groupId>
-        <artifactId>jmh-core</artifactId>
-        <version>1.21</version>
-    </dependency>
+            <groupId>org.openjdk.jmh</groupId>
+            <artifactId>jmh-core</artifactId>
+            <version>1.35</version>
+        </dependency>
         <dependency>
             <groupId>org.openjdk.jmh</groupId>
             <artifactId>jmh-generator-annprocess</artifactId>
-            <version>1.21</version>
+            <version>1.35</version>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
diff --git a/benchmark/src/main/java/org/apache/james/mime4j/JMHFieldBench.java 
b/benchmark/src/main/java/org/apache/james/mime4j/JMHFieldBench.java
new file mode 100644
index 00000000..df211b94
--- /dev/null
+++ b/benchmark/src/main/java/org/apache/james/mime4j/JMHFieldBench.java
@@ -0,0 +1,114 @@
+/****************************************************************
+ * 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   *
+ *                                                              *
+ *   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.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.mime4j.codec.DecodeMonitor;
+import org.apache.james.mime4j.field.AddressListFieldImpl;
+import org.apache.james.mime4j.field.AddressListFieldLenientImpl;
+import org.apache.james.mime4j.field.ContentDispositionFieldImpl;
+import org.apache.james.mime4j.field.ContentDispositionFieldLenientImpl;
+import org.apache.james.mime4j.field.ContentTypeFieldImpl;
+import org.apache.james.mime4j.field.ContentTypeFieldLenientImpl;
+import org.apache.james.mime4j.field.DateTimeFieldImpl;
+import org.apache.james.mime4j.field.DateTimeFieldLenientImpl;
+import org.apache.james.mime4j.stream.RawField;
+import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.openjdk.jmh.runner.options.TimeValue;
+
+public class JMHFieldBench {
+    @Test
+    public void launchBenchmark() throws Exception {
+        Options opt = new OptionsBuilder()
+            .include(this.getClass().getName() + ".*")
+            .mode (Mode.AverageTime)
+            .timeUnit(TimeUnit.MICROSECONDS)
+            .warmupTime(TimeValue.seconds(5))
+            .warmupIterations(3)
+            .measurementTime(TimeValue.seconds(2))
+            .measurementIterations(5)
+            .threads(1)
+            .forks(1)
+            .shouldFailOnError(true)
+            .shouldDoGC(true)
+            .build();
+
+        new Runner(opt).run();
+    }
+
+    @Benchmark
+    public void dateLenient(Blackhole bh) {
+        bh.consume(DateTimeFieldLenientImpl.PARSER.parse(new RawField("Date", 
"Tue, 26 Apr 2022 02:27:54 +0000"), DecodeMonitor.SILENT)
+            .getDate());
+    }
+
+    @Benchmark
+    public void dateStrict(Blackhole bh) {
+        bh.consume(DateTimeFieldImpl.PARSER.parse(new RawField("Date", "Tue, 
26 Apr 2022 02:27:54 +0000"), DecodeMonitor.SILENT)
+            .getDate());
+    }
+
+    @Benchmark
+    public void mailboxLenient(Blackhole bh) {
+        bh.consume(AddressListFieldLenientImpl.PARSER.parse(new 
RawField("From", "Me <m...@example.com>, \"You\" <y...@exemple.com>"), 
DecodeMonitor.SILENT).getAddressList());
+    }
+
+    @Benchmark
+    public void mailboxStrict(Blackhole bh) {
+        bh.consume(AddressListFieldImpl.PARSER.parse(new RawField("From", "Me 
<m...@example.com>, \"You\" <y...@exemple.com>"), 
DecodeMonitor.SILENT).getAddressList());
+    }
+
+    @Benchmark
+    public void contentTypeLenient(Blackhole bh) {
+        bh.consume(ContentTypeFieldLenientImpl.PARSER.parse(new 
RawField("Content-Type", "multipart/mixed; 
boundary=\"------------090404080405080108000909\""), 
DecodeMonitor.SILENT).getBoundary());
+    }
+
+    @Benchmark
+    public void contentTypeLenientFolded(Blackhole bh) {
+        bh.consume(ContentTypeFieldLenientImpl.PARSER.parse(new 
RawField("Content-Type", "multipart/mixed;\r\n 
boundary=\"------------090404080405080108000909\""), 
DecodeMonitor.SILENT).getBoundary());
+    }
+
+    @Benchmark
+    public void contentTypeStrictFolded(Blackhole bh) {
+        bh.consume(ContentTypeFieldImpl.PARSER.parse(new 
RawField("Content-Type", "multipart/mixed;\r\n 
boundary=\"------------090404080405080108000909\""), 
DecodeMonitor.SILENT).getBoundary());
+    }
+
+    @Benchmark
+    public void contentTypeStrict(Blackhole bh) {
+        bh.consume(ContentTypeFieldImpl.PARSER.parse(new 
RawField("Content-Type", "multipart/mixed; 
boundary=\"------------090404080405080108000909\""), 
DecodeMonitor.SILENT).getBoundary());
+    }
+
+    @Benchmark
+    public void contentDispositionLenient(Blackhole bh) {
+        bh.consume(ContentDispositionFieldLenientImpl.PARSER.parse(new 
RawField("Content-Disposition", "attachment; filename=blob.png"), 
DecodeMonitor.SILENT).getFilename());
+    }
+
+    @Benchmark
+    public void contentDispositionStrict(Blackhole bh) {
+        bh.consume(ContentDispositionFieldImpl.PARSER.parse(new 
RawField("Content-Disposition", "attachment; filename=blob.png"), 
DecodeMonitor.SILENT).getFilename());
+    }
+}
diff --git 
a/benchmark/src/main/java/org/apache/james/mime4j/JMHLongMultipartReadBench.java
 
b/benchmark/src/main/java/org/apache/james/mime4j/JMHLongMultipartReadBench.java
index e2fa5673..1e7efa8c 100644
--- 
a/benchmark/src/main/java/org/apache/james/mime4j/JMHLongMultipartReadBench.java
+++ 
b/benchmark/src/main/java/org/apache/james/mime4j/JMHLongMultipartReadBench.java
@@ -61,7 +61,7 @@ public class JMHLongMultipartReadBench {
     public void launchBenchmark() throws Exception {
         Options opt = new OptionsBuilder()
             .include(this.getClass().getName() + ".benchmark*")
-            .mode (Mode.AverageTime)
+            .mode(Mode.AverageTime)
             .addProfiler(GCProfiler.class)
             .timeUnit(TimeUnit.MICROSECONDS)
             .warmupTime(TimeValue.seconds(5))


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to