Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions eo-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ SOFTWARE.
<artifactId>xsline</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>com.github.volodya-lombrozo</groupId>
<artifactId>xnav</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
Expand Down Expand Up @@ -131,18 +136,6 @@ SOFTWARE.
<!-- version from parent POM -->
<scope>test</scope>
</dependency>
<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>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
Expand Down Expand Up @@ -173,6 +166,18 @@ SOFTWARE.
<artifactId>mktmp</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>farea</artifactId>
<version>0.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.15.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
22 changes: 15 additions & 7 deletions eo-parser/src/main/java/org/eolang/parser/Xmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.parser;

import com.github.lombrozo.xnav.Xnav;
import com.jcabi.xml.XML;
import com.yegor256.xsline.Shift;
import com.yegor256.xsline.StClasspath;
Expand Down Expand Up @@ -162,7 +163,8 @@ public Collection<SAXParseException> validate(final XML xsd) {
*/
public String toEO() {
return this.converted(
Xmir.FOR_EO, "/org/eolang/parser/print/to-eo.xsl", "eo/text()"
Xmir.FOR_EO, "/org/eolang/parser/print/to-eo.xsl",
"eo"
);
}

Expand All @@ -172,7 +174,8 @@ public String toEO() {
*/
public String toReversedEO() {
return this.converted(
Xmir.FOR_EO, "/org/eolang/parser/print/to-eo-reversed.xsl", "eo/text()"
Xmir.FOR_EO, "/org/eolang/parser/print/to-eo-reversed.xsl",
"eo"
);
}

Expand Down Expand Up @@ -201,7 +204,7 @@ public String toPhi(final boolean conservative) {
)
)
),
"program/phi/text()"
"phi"
);
}

Expand All @@ -211,7 +214,8 @@ public String toPhi(final boolean conservative) {
*/
public String toSaltyPhi() {
return this.converted(
Xmir.FOR_PHI, "/org/eolang/parser/phi/to-salty-phi.xsl", "program/phi/text()"
Xmir.FOR_PHI, "/org/eolang/parser/phi/to-salty-phi.xsl",
"phi"
);
}

Expand All @@ -229,10 +233,14 @@ private String converted(final Train<Shift> train, final String xsl, final Strin
/**
* Converts XMIR.
* @param train Train of transformations that prepares XMIR
* @param xpath Xpath to retrieve the final result
* @param node XML node name
* @return XMIR in other representation as {@link String}.
*/
private String converted(final Train<Shift> train, final String xpath) {
return new Xsline(train).pass(this.xml).xpath(xpath).get(0);
private String converted(final Train<Shift> train, final String node) {
return new Xnav(new Xsline(train).pass(this.xml).inner())
.element("program")
.element(node)
.text()
.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ SOFTWARE.
<xsl:output method="text" encoding="UTF-8"/>
<!-- PROGRAM -->
<xsl:template match="program">
<eo>
<xsl:apply-templates select="license"/>
<xsl:apply-templates select="metas"/>
<xsl:apply-templates select="objects"/>
</eo>
<program>
<eo>
<xsl:apply-templates select="license"/>
<xsl:apply-templates select="metas"/>
<xsl:apply-templates select="objects"/>
</eo>
</program>
</xsl:template>
<!-- LICENCE -->
<xsl:template match="license">
Expand Down
12 changes: 7 additions & 5 deletions eo-parser/src/main/resources/org/eolang/parser/print/to-eo.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ SOFTWARE.
<xsl:output method="text" encoding="UTF-8"/>
<!-- PROGRAM -->
<xsl:template match="program">
<eo>
<xsl:apply-templates select="license"/>
<xsl:apply-templates select="metas"/>
<xsl:apply-templates select="objects"/>
</eo>
<program>
<eo>
<xsl:apply-templates select="license"/>
<xsl:apply-templates select="metas"/>
<xsl:apply-templates select="objects"/>
</eo>
</program>
</xsl:template>
<!-- LICENCE -->
<xsl:template match="license">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,68 +21,60 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.parser;
package benchmarks;

import com.jcabi.xml.XMLDocument;
import com.yegor256.xsline.StClasspath;
import java.io.IOException;
import com.jcabi.xml.XML;
import fixtures.LargeXmir;
import java.util.concurrent.TimeUnit;
import org.cactoos.io.ResourceOf;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.Main;
import org.eolang.parser.Xmir;
import org.openjdk.jmh.annotations.Benchmark;
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.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

/**
* Benchmark for XSL transformations.
* Benchmark for XMIR to EO and to Phi transformations.
*
* @since 0.41
* @checkstyle DesignForExtensionCheck (100 lines)
* @checkstyle NonStaticMethodCheck (100 lines)
*/
@Fork(1)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.MILLISECONDS)
@Fork(1)
@State(Scope.Benchmark)
@Disabled
@SuppressWarnings({
"JTCOP.RuleAllTestsHaveProductionClass",
"PMD.JUnitTestClassShouldBeFinal",
"PMD.JUnit5TestShouldBePackagePrivate"
})
public class XslBenchmarkIT {
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleCorrectTestName"})
public class XmirBench {

/**
* Pairs of XSL and worst XMIR for the XSL.
* Large XMIR document.
*/
@Param({
"/org/eolang/parser/shake/add-default-package.xsl|org/eolang/parser/benchmark/native.xmir",
"/org/eolang/parser/shake/build-fqns.xsl|org/eolang/parser/benchmark/native.xmir",
"/org/eolang/parser/shake/explicit-data.xsl|org/eolang/parser/benchmark/native.xmir"
})
private String pairs;
private static final XML XMIR = new LargeXmir("noname", "com/sun/jna/Klass.class").xml();

@Benchmark
public void apply() throws Exception {
final String[] pair = this.pairs.split("\\|");
new StClasspath(pair[0]).apply(
1, new XMLDocument(new ResourceOf(pair[1]).stream())
);
public void xmirToEO() {
new Xmir(XmirBench.XMIR).toEO();
}

@Test
@SuppressWarnings("JTCOP.LineHitterRule")
void measuresXslTransformations() throws IOException {
Main.main(new String[0]);
Assertions.assertTrue(true, "Benchmark should executed");
@Benchmark
public void xmirToReversedEo() {
new Xmir(XmirBench.XMIR).toReversedEO();
}

@Benchmark
public void xmirToPhi() {
new Xmir(XmirBench.XMIR).toPhi();
}

@Benchmark
public void xmirToSaltyPhi() {
new Xmir(XmirBench.XMIR).toSaltyPhi();
}
}
82 changes: 82 additions & 0 deletions eo-parser/src/test/java/benchmarks/XslBench.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2025 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package benchmarks;

import com.jcabi.xml.XML;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.Xsline;
import fixtures.LargeXmir;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
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;

/**
* Benchmark for XSL transformations.
*
* @since 0.41
* @checkstyle NonStaticMethodCheck (100 lines)
*/
@Fork(1)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleCorrectTestName"})
public class XslBench {

/**
* Large XMIR document.
*/
private static final XML INPUT = new LargeXmir().xml();

/**
* All sheets to use.
*/
private static final Xsline LINE = new Xsline(
new TrClasspath<>(
"/org/eolang/parser/parse/move-voids-up.xsl",
"/org/eolang/parser/parse/validate-before-stars.xsl",
"/org/eolang/parser/parse/resolve-before-star.xsl",
"/org/eolang/parser/parse/wrap-method-calls.xsl",
"/org/eolang/parser/parse/const-to-dataized.xsl",
"/org/eolang/parser/parse/stars-to-tuples.xsl",
"/org/eolang/parser/shake/add-default-package.xsl",
"/org/eolang/parser/shake/build-fqns.xsl",
"/org/eolang/parser/shake/explicit-data.xsl"
).back()
);

@Benchmark
public final void manySheetsOnLargeXmir() {
XslBench.LINE.pass(XslBench.INPUT);
}
}
30 changes: 30 additions & 0 deletions eo-parser/src/test/java/benchmarks/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2025 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Benchmarks.
*
* @since 0.51
*/
package benchmarks;
Loading