mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Merge performance into latest
This commit is contained in:
commit
e1532885dc
@ -37,4 +37,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.12'
|
||||
testCompile group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.12'
|
||||
}
|
||||
|
@ -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=
|
||||
|
@ -82,9 +82,9 @@ public final class std_range implements Function {
|
||||
|
||||
private boolean isIntegerRange() {
|
||||
if (to > 0) {
|
||||
return (to < Integer.MAX_VALUE) && (from > Integer.MIN_VALUE && to < Integer.MAX_VALUE);
|
||||
return (from > Integer.MIN_VALUE && to < Integer.MAX_VALUE);
|
||||
}
|
||||
return (to > Integer.MIN_VALUE) && (to > Integer.MIN_VALUE && from < Integer.MAX_VALUE);
|
||||
return (to > Integer.MIN_VALUE && from < Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,7 +203,7 @@ public final class Lexer {
|
||||
clearBuffer();
|
||||
while (true) {
|
||||
final String text = buffer.toString();
|
||||
if (!OPERATORS.containsKey(text + current) && !text.isEmpty()) {
|
||||
if (!text.isEmpty() && !OPERATORS.containsKey(text + current)) {
|
||||
addToken(OPERATORS.get(text));
|
||||
return;
|
||||
}
|
||||
@ -237,9 +237,9 @@ public final class Lexer {
|
||||
clearBuffer();
|
||||
char current = peek(0);
|
||||
while (true) {
|
||||
if (current == '`') break;
|
||||
if (current == '\0') throw error("Reached end of file while parsing extended word.");
|
||||
if (current == '\n' || current == '\r') throw error("Reached end of line while parsing extended word.");
|
||||
if (current == '`') break;
|
||||
buffer.append(current);
|
||||
current = next();
|
||||
}
|
||||
@ -252,7 +252,6 @@ public final class Lexer {
|
||||
clearBuffer();
|
||||
char current = peek(0);
|
||||
while (true) {
|
||||
if (current == '\0') throw error("Reached end of file while parsing text string.");
|
||||
if (current == '\\') {
|
||||
current = next();
|
||||
switch (current) {
|
||||
@ -288,6 +287,7 @@ public final class Lexer {
|
||||
continue;
|
||||
}
|
||||
if (current == '"') break;
|
||||
if (current == '\0') throw error("Reached end of file while parsing text string.");
|
||||
buffer.append(current);
|
||||
current = next();
|
||||
}
|
||||
@ -306,8 +306,8 @@ public final class Lexer {
|
||||
private void tokenizeMultilineComment() {
|
||||
char current = peek(0);
|
||||
while (true) {
|
||||
if (current == '\0') throw error("Reached end of file while parsing multiline comment");
|
||||
if (current == '*' && peek(1) == '/') break;
|
||||
if (current == '\0') throw error("Reached end of file while parsing multiline comment");
|
||||
current = next();
|
||||
}
|
||||
next(); // *
|
||||
|
@ -6,6 +6,7 @@ import com.annimon.ownlang.lib.StringValue;
|
||||
import com.annimon.ownlang.lib.UserDefinedFunction;
|
||||
import com.annimon.ownlang.parser.ast.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -26,10 +27,10 @@ public final class Parser {
|
||||
}
|
||||
|
||||
private static final Token EOF = new Token(TokenType.EOF, "", -1, -1);
|
||||
|
||||
private static final Map<TokenType, BinaryExpression.Operator> assignOperator;
|
||||
|
||||
private static final EnumMap<TokenType, BinaryExpression.Operator> assignOperator;
|
||||
static {
|
||||
assignOperator = new HashMap<>(BinaryExpression.Operator.values().length + 1);
|
||||
assignOperator = new EnumMap(TokenType.class);
|
||||
assignOperator.put(TokenType.EQ, null);
|
||||
assignOperator.put(TokenType.PLUSEQ, BinaryExpression.Operator.ADD);
|
||||
assignOperator.put(TokenType.MINUSEQ, BinaryExpression.Operator.SUBTRACT);
|
||||
|
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