Skip to content

Commit

Permalink
Merge pull request #184 from h1alexbel/144
Browse files Browse the repository at this point in the history
feat(#144): Each Lint timings in benchmark
  • Loading branch information
yegor256 authored Dec 31, 2024
2 parents 75cb4ab + 590ac1e commit 4e8a1b6
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ jobs:
printf "\`\`\`text\n"
cat target/lint-summary.txt
printf "\n\n"
header=true
while IFS=, read -r id ms; do
if [[ "$id" != "id" ]]; then
if $header; then
header=false
continue
fi
printf "%s (%s ms)\n" "$(echo "$id" | tr -d '"')" "$(echo "$ms" | tr -d '"')"
fi
done < target/timings.csv
printf "\n\n"
printf "\`\`\`\n\n"
echo "The results were calculated in [this GHA job][benchmark-gha]"
echo "on $(date +'%Y-%m-%d') at $(date +'%H:%M'),"
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ SOFTWARE.
<version>0.50.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>tojos</artifactId>
<version>0.18.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>mktmp</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/eolang/lints/Lint.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
*/
public interface Lint<T> {

/**
* Name of the lint.
* @return Lint name
*/
String name();

/**
* Find and return defects.
* @param entity The entity to analyze (could be {@link com.jcabi.xml.XML}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/eolang/lints/LtByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ final class LtByXsl implements Lint<XML> {
this.doc = motive;
}

@Override
public String name() {
return this.rule;
}

@Override
public Collection<Defect> defects(final XML xmir) {
final XML report = this.sheet.transform(xmir);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/lints/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Program(final XML xml) {
}

/**
* Find defects possible defects in the XM§IR file.
* Find defects possible defects in the XMIR file.
* @return All defects found
*/
public Collection<Defect> defects() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/eolang/lints/comments/LtAsciiOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public Collection<Defect> defects(final XML xmir) throws IOException {
return defects;
}

@Override
public String name() {
return "ascii-only";
}

@Override
public String motive() throws Exception {
return new TextOf(
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/eolang/lints/misc/LtTestNotVerb.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public String motive() throws Exception {
).asString();
}

@Override
public String name() {
return "unit-test-is-not-verb";
}

/**
* Prestructor for default properties.
* @return Properties.
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/eolang/lints/units/LtUnitTestMissing.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public Collection<Defect> defects(final Map<String, XML> pkg) throws IOException
return defects;
}

@Override
public String name() {
return "unit-test-missing";
}

@Override
public String motive() throws Exception {
return "";
Expand Down
92 changes: 85 additions & 7 deletions src/test/java/org/eolang/lints/ProgramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@
import com.yegor256.MktmpResolver;
import com.yegor256.Together;
import com.yegor256.farea.Farea;
import com.yegor256.tojos.MnCsv;
import com.yegor256.tojos.TjCached;
import com.yegor256.tojos.TjDefault;
import com.yegor256.tojos.Tojos;
import com.yegor256.xsline.Xsline;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import org.cactoos.io.InputOf;
import org.cactoos.io.ResourceOf;
import org.cactoos.iterable.Sticky;
import org.cactoos.iterable.Synced;
import org.cactoos.set.SetOf;
import org.eolang.parser.EoSyntax;
import org.eolang.parser.TrParsing;
Expand All @@ -60,12 +67,6 @@
* other classes in size too, for instance smaller classes (standard program),
* large class (JNA pointer), x-large class, and xxl class. Don't forget to
* adjust lint-summary.txt file to capture all the measurements.
* @todo #134:90min Capture all the lint timings in timings.csv.
* Currently, we just capture total time - amount of milliseconds was required
* to lint some XMIR. Would be helpful to get extended statistics - timings of
* each lint. Don't forget to include this information into lint-summary.txt.
* You can check how it was implemented in HONE:
* <a href="https://github.com/objectionary/hone-maven-plugin/blob/master/src/main/java/org/eolang/hone/Timings.java">Timings.java</a>.
*/
@ExtendWith(MktmpResolver.class)
final class ProgramTest {
Expand Down Expand Up @@ -231,7 +232,7 @@ void lintsLargeJnaClass(@Mktmp final Path home) throws Exception {
).path();
final XML xmir = new XMLDocument(pre);
final long start = System.currentTimeMillis();
final Collection<Defect> defects = new Program(xmir).defects();
final Collection<Defect> defects = new ProgramTest.BcProgram(xmir).defects();
final long msec = System.currentTimeMillis() - start;
final Path target = Paths.get("target");
Files.write(
Expand Down Expand Up @@ -262,4 +263,81 @@ void lintsLargeJnaClass(@Mktmp final Path home) throws Exception {
}
);
}

/**
* Benchmarked program.
* @since 0.0.29
*/
private static final class BcProgram {

/**
* XMIR.
*/
private final XML xmir;

/**
* Lints to apply.
*/
private final Iterable<Lint<XML>> lints;

/**
* Timings.
*/
private final Tojos timings;

/**
* Ctor.
* @param program XMIR program to lint
*/
BcProgram(final XML program) {
this(
program,
new Synced<>(new Sticky<>(new PkMono())),
new TjCached(
new TjDefault(
new MnCsv("target/timings.csv")
)
)
);
}

/**
* Ctor.
* @param program XMIR program to lint
* @param lnts Lints to apply
* @param tmngs Timings
*/
BcProgram(final XML program, final Iterable<Lint<XML>> lnts, final Tojos tmngs) {
this.xmir = program;
this.lints = lnts;
this.timings = tmngs;
}

/**
* Defects.
* @return Defects
* @todo #144:35min Resolve code duplication with Program.java class.
* Currently, BcProgram.java is duplication of Program.java. Let's make
* it use the original Program.java, so they will stay synced. Don't forget
* to remove this puzzle.
*/
public Collection<Defect> defects() {
try {
final Collection<Defect> messages = new ArrayList<>(0);
for (final Lint<XML> lint : this.lints) {
final long start = System.currentTimeMillis();
final Collection<Defect> defects = lint.defects(this.xmir);
final long done = System.currentTimeMillis() - start;
this.timings.add(lint.name()).set("ms", done);
messages.addAll(defects);
}
return messages;
} catch (final IOException ex) {
throw new IllegalStateException(
"Failed to find defects in the XMIR file",
ex
);
}
}
}
}

2 comments on commit 4e8a1b6

@0pdd
Copy link

@0pdd 0pdd commented on 4e8a1b6 Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 134-6deff79b disappeared from src/test/java/org/eolang/lints/ProgramTest.java), that's why I closed #144. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 4e8a1b6 Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 144-43965ba3 discovered in src/test/java/org/eolang/lints/ProgramTest.java) and submitted as #190. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.