Skip to content

Commit 6286182

Browse files
committed
bench
1 parent d48c39e commit 6286182

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

src/main/java/org/eolang/lints/errors/LtObjectIsNotUnique.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ private static Map<String, String> programObjects(final XML xmir) {
119119
.collect(
120120
Collectors.toMap(
121121
names::get,
122-
pos -> xmir.xpath("/program/objects/o/@line").get(pos),
122+
pos -> xmir.xpath(
123+
String.format("/program/objects/o[%d]/@line", pos + 1)
124+
).stream().findFirst().orElse("0"),
123125
(existing, replacement) -> replacement
124126
)
125127
);

src/test/java/benchmarks/ProgramBench.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
@Fork(1)
5050
@BenchmarkMode(Mode.AverageTime)
5151
@OutputTimeUnit(TimeUnit.MILLISECONDS)
52-
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.MILLISECONDS)
53-
@Measurement(iterations = 2, time = 1, timeUnit = TimeUnit.MILLISECONDS)
52+
@Warmup(iterations = 1)
53+
@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS)
5454
@State(Scope.Benchmark)
5555
public class ProgramBench {
5656

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2025 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package benchmarks;
25+
26+
import fixtures.LargeXmir;
27+
import java.io.IOException;
28+
import java.nio.charset.StandardCharsets;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
31+
import java.util.concurrent.TimeUnit;
32+
import org.cactoos.scalar.IoChecked;
33+
import org.eolang.lints.Program;
34+
import org.eolang.lints.Programs;
35+
import org.openjdk.jmh.annotations.Benchmark;
36+
import org.openjdk.jmh.annotations.BenchmarkMode;
37+
import org.openjdk.jmh.annotations.Fork;
38+
import org.openjdk.jmh.annotations.Measurement;
39+
import org.openjdk.jmh.annotations.Mode;
40+
import org.openjdk.jmh.annotations.OutputTimeUnit;
41+
import org.openjdk.jmh.annotations.Scope;
42+
import org.openjdk.jmh.annotations.State;
43+
import org.openjdk.jmh.annotations.Warmup;
44+
45+
/**
46+
* Benchmark for {@link Program}.
47+
*
48+
* @since 0.0.34
49+
* @checkstyle DesignForExtensionCheck (10 lines)
50+
* @checkstyle NonStaticMethodCheck (100 lines)
51+
*/
52+
@Fork(1)
53+
@BenchmarkMode(Mode.AverageTime)
54+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
55+
@Warmup(iterations = 1)
56+
@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS)
57+
@State(Scope.Benchmark)
58+
public class ProgramsBench {
59+
60+
/**
61+
* Large XMIR document.
62+
*/
63+
private final Path home;
64+
65+
public ProgramsBench() {
66+
try {
67+
this.home = Files.createTempDirectory("tmp");
68+
for (int idx = 0; idx < 10; ++idx) {
69+
final String name = String.format("program-%d.xmir", idx);
70+
Files.write(
71+
this.home.resolve(String.format("%s.xmir", name)),
72+
new IoChecked<>(new LargeXmir(name))
73+
.value().toString().getBytes(StandardCharsets.UTF_8)
74+
);
75+
}
76+
} catch (final IOException ex) {
77+
throw new IllegalArgumentException(ex);
78+
}
79+
}
80+
81+
@Benchmark
82+
public final void scansLargeProgram() throws IOException {
83+
new Programs(this.home).defects();
84+
}
85+
}

src/test/java/fixtures/LargeXmir.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.cactoos.bytes.BytesOf;
3434
import org.cactoos.bytes.UncheckedBytes;
3535
import org.cactoos.io.ResourceOf;
36+
import org.xembly.Directives;
37+
import org.xembly.Xembler;
3638

3739
/**
3840
* Large XMIR document.
@@ -41,6 +43,16 @@
4143
*/
4244
public final class LargeXmir implements Scalar<XML> {
4345

46+
private final String name;
47+
48+
public LargeXmir() {
49+
this("unknown");
50+
}
51+
52+
public LargeXmir(final String nme) {
53+
this.name = nme;
54+
}
55+
4456
@Override
4557
public XML value() throws Exception {
4658
final Path home = Files.createTempDirectory("tmp");
@@ -76,6 +88,10 @@ public XML value() throws Exception {
7688
);
7789
}
7890
);
79-
return ref.get();
91+
final XML xml = ref.get();
92+
new Xembler(
93+
new Directives().xpath("/program").attr("name", this.name)
94+
).apply(xml.inner());
95+
return xml;
8096
}
8197
}

0 commit comments

Comments
 (0)