Skip to content

Commit

Permalink
Add benchmark for UriParser
Browse files Browse the repository at this point in the history
  • Loading branch information
japplis authored and raboof committed Jul 6, 2024
1 parent 4b02af2 commit 0619860
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
66 changes: 66 additions & 0 deletions commons-vfs2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@
<artifactId>httpcore-nio</artifactId>
<scope>test</scope>
</dependency>
<!-- JMH Performance tests -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down Expand Up @@ -352,6 +358,66 @@
</plugins>
</build>
</profile>
<!-- Profile to build and run the benchmarks. Use 'mvn test -Pbenchmark', and add '-Dbenchmark=foo' to run only the foo benchmark -->
<profile>
<id>benchmark</id>

<properties>
<skipTests>true</skipTests>
<benchmark>org.apache</benchmark>
</properties>

<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Enable the compilation of the benchmarks -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${commons.compiler.version}</version>
<configuration combine.self="override">
<testIncludes>
<testInclude>**/*</testInclude>
</testIncludes>
</configuration>
</plugin>
<!-- Hook the benchmarks to the test phase -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>benchmark</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>org.openjdk.jmh.Main</argument>
<argument>-rf</argument>
<argument>json</argument>
<argument>-rff</argument>
<argument>target/jmh-result.json</argument>
<argument>${benchmark}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.commons.vfs2.provider;

import org.apache.commons.vfs2.FileSystemException;
import org.openjdk.jmh.annotations.*;

@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 2)
@Measurement(iterations = 5)
public class UriParserBenchmark {

private static final String PATH_TO_NORMALIZE = "file:///this/../is/a%2flong%2Fpath/./for testing/normlisePath%2fmethod.txt";

@Benchmark
public void normalisePath() throws FileSystemException {
StringBuilder path = new StringBuilder(PATH_TO_NORMALIZE);
UriParser.fixSeparators(path);
UriParser.normalisePath(path);
}
}
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<!-- JMH Performance tests -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.37</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.37</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 0619860

Please sign in to comment.