mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Добавлены JMH-бенчмарки
This commit is contained in:
parent
ee57957140
commit
4df44cadea
@ -50,7 +50,8 @@ javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}:\
|
||||
${libs.junit_4.classpath}:\
|
||||
${libs.hamcrest.classpath}
|
||||
${libs.hamcrest.classpath}:\
|
||||
${libs.JMH_1.12.classpath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
|
48
test/com/annimon/ownlang/parser/LexerBenchmarkTest.java
Normal file
48
test/com/annimon/ownlang/parser/LexerBenchmarkTest.java
Normal file
@ -0,0 +1,48 @@
|
||||
package com.annimon.ownlang.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
@Ignore
|
||||
public class LexerBenchmarkTest {
|
||||
|
||||
@Param({"1000"})
|
||||
private int iterations;
|
||||
|
||||
private String input;
|
||||
|
||||
@Setup(Level.Trial)
|
||||
public void initializeTrial() throws IOException {
|
||||
input = SourceLoader.readSource("program.own");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void lexerBenchmark() {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
Lexer.tokenize(input);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeBenchmark() throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(LexerBenchmarkTest.class.getSimpleName())
|
||||
.warmupIterations(3)
|
||||
.measurementIterations(5)
|
||||
.threads(1)
|
||||
.forks(1)
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
50
test/com/annimon/ownlang/parser/ParserBenchmarkTest.java
Normal file
50
test/com/annimon/ownlang/parser/ParserBenchmarkTest.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.annimon.ownlang.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@State(Scope.Benchmark)
|
||||
@Ignore
|
||||
public class ParserBenchmarkTest {
|
||||
|
||||
@Param({"1000"})
|
||||
private int iterations;
|
||||
|
||||
private List<Token> input;
|
||||
|
||||
@Setup(Level.Trial)
|
||||
public void initializeTrial() throws IOException {
|
||||
input = Lexer.tokenize(SourceLoader.readSource("program.own"));
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void parserBenchmark(Blackhole bh) {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
bh.consume(Parser.parse(input));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeBenchmark() throws RunnerException {
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(ParserBenchmarkTest.class.getSimpleName())
|
||||
.warmupIterations(3)
|
||||
.measurementIterations(5)
|
||||
.threads(1)
|
||||
.forks(1)
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user