Skip to content

Commit

Permalink
Adjust Parser Benchmark to measure deeply nested structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
joehni committed Oct 30, 2024
1 parent abe035c commit 08524e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 3 additions & 3 deletions xstream-jmh/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!--
Copyright (C) 2015, 2017, 2018, 2019, 2020, 2021, 2022, 2023 XStream committers.
Copyright (C) 2015, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 XStream committers.
All rights reserved.
The software in this package is published under the terms of the BSD
Expand Down Expand Up @@ -140,7 +140,7 @@
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
<scope>runtime</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
Expand All @@ -165,7 +165,7 @@
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<scope>runtime</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, 2017, 2021 XStream Committers.
* Copyright (C) 2015, 2017, 2021, 2024 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -18,6 +18,9 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.xml.stream.XMLInputFactory;

import org.codehaus.jettison.json.JSONObject;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -33,6 +36,7 @@
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.BenchmarkParams;

import com.ctc.wstx.api.WstxInputProperties;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
Expand Down Expand Up @@ -69,6 +73,10 @@
@Threads(1)
@Warmup(iterations = 5)
public class ParserBenchmark {
{
// Increase max recursion depth for Jettison
JSONObject.setGlobalRecursionDepthLimit(2000);
}

/**
* Driver factory. Enum values used as parameter for the parser benchmark methods.
Expand Down Expand Up @@ -106,7 +114,15 @@ public enum DriverFactory {
*
* @since 1.4.9
*/
Woodstox(new WstxDriver()), //
Woodstox(new WstxDriver() {
@Override
protected XMLInputFactory createInputFactory() {
final XMLInputFactory inputFactory = super.createInputFactory();
// Increase max recursion depth for Woodstox
inputFactory.setProperty(WstxInputProperties.P_MAX_ELEMENT_DEPTH, Integer.valueOf(2000));
return inputFactory;
}
}), //
/**
* Factory for the {@link BEAStaxDriver}.
*
Expand Down Expand Up @@ -163,7 +179,7 @@ public HierarchicalStreamWriter createWriter(final Writer out) {

private final HierarchicalStreamDriver driver;

private DriverFactory(final HierarchicalStreamDriver driver) {
DriverFactory(final HierarchicalStreamDriver driver) {
this.driver = driver;
}

Expand Down Expand Up @@ -229,7 +245,7 @@ public void checkData(final Object o) {
}
},
/**
* Nested list in list structure, 500 elements deep.
* Nested list in list structure, 1000 elements deep.
*
* @author J&ouml;rg Schaible
* @since 1.4.9
Expand Down Expand Up @@ -294,6 +310,7 @@ public void checkData(final Object o) {
assert 0 == array[LENGTH - 1] : ManyChildren + " fails end";
}
};

/**
* Write the data of the factory into the writer of the hierarchical stream.
*
Expand Down Expand Up @@ -331,6 +348,7 @@ public void init() {
xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
xstream.allowTypes(List.class, String.class);
xstream.setMode(XStream.NO_REFERENCES);
xstream.setCollectionUpdateLimit(0);
driver = driverFactory.getDriver();
}

Expand Down

0 comments on commit 08524e5

Please sign in to comment.