Skip to content

Commit

Permalink
fix bench
Browse files Browse the repository at this point in the history
  • Loading branch information
bachish committed May 6, 2024
1 parent e1cf245 commit 7ec7b19
Show file tree
Hide file tree
Showing 10 changed files with 819 additions and 892 deletions.
2 changes: 1 addition & 1 deletion benchmarks/src/main/java/org/ucfs/Java.x
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Comment = {TraditionalComment} | {DocumentationComment}
TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/"
DocumentationComment = "/**" {CommentContent} "*"+ "/"
CommentContent = ( [^*] | \*+ [^/*] )*
%%
"//".* { /* DO NOTHING */ }
"boolean" { return JavaToken.BOOLEAN; }
"byte" { return JavaToken.BYTE; }
"short" { return JavaToken.SHORT; }
Expand Down
1,578 changes: 772 additions & 806 deletions benchmarks/src/main/java/org/ucfs/JavaLexer.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmarks/src/main/kotlin/org/Benchmarks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun <G : IInputGraph<Int, LinearInputLabel>> getTokenStream(input: String, input
while (true) {
token = lexer.yylex() as JavaToken
if (token == JavaToken.EOF) break
inputGraph.addEdge(vertexId, LinearInputLabel(Term(token)), ++vertexId)
inputGraph.addEdge(vertexId, LinearInputLabel(token), ++vertexId)
}

return inputGraph
Expand Down
74 changes: 0 additions & 74 deletions benchmarks/src/main/kotlin/org/Jmh.kt

This file was deleted.

21 changes: 19 additions & 2 deletions benchmarks/src/main/kotlin/org/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,25 @@ class Main {
fun main(){
val startState = Java8().rsm
val srcText: String = """
package junit;"""
package junit.runner;
/**
* This class defines the current version of JUnit
*/
public class Version {
private Version() {
// don't instantiate
}
public static String id() {
return "4.12-SNAPSHOT";
}
public static void main(String[] args) {
System.out.println(id());
}
}
"""
val tokens = getTokenStream(srcText)
val gll = Gll.gll(
startState,
Expand All @@ -24,5 +42,4 @@ package junit;"""
val parseResult = gll.parse().first ?: throw Exception("File $srcText cant be parsed by online gll")
writeSppfToDot(parseResult, "java7.dot")

//val efileContents = buildStringFromSppf(parseResult)
}
14 changes: 8 additions & 6 deletions benchmarks/src/main/kotlin/org/OnlineGllBench.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org
import kotlinx.benchmark.*
import org.openjdk.jmh.annotations.Threads
import org.ucfs.Java8
import org.ucfs.input.LinearInput
import org.ucfs.input.LinearInputLabel
import org.ucfs.parser.Gll
import org.ucfs.sppf.buildStringFromSppf

Expand All @@ -22,23 +24,23 @@ class OnlineGllBench {
lateinit var fileContents: String

val startState = Java8().rsm
lateinit var tokens: LinearInput<Int, LinearInputLabel>

@Setup
fun prepare() {
val srcText: String = OnlineGllBench::class.java.classLoader
fileContents = OnlineGllBench::class.java.classLoader
.getResource(fileName)?.readText() ?: throw Exception("File $fileName does not exists")
tokens = getTokenStream(fileContents)
val gll = Gll.gll(
startState,
getTokenStream(srcText)
tokens
)
val parseResult = gll.parse().first ?: throw Exception("File $fileName cant be parsed by online gll")
fileContents = buildStringFromSppf(parseResult)
gll.parse().first ?: throw Exception("File $fileName cant be parsed by online gll")
}

@Benchmark
fun measureGll(blackhole: Blackhole) {
val inputGraph = getTokenStream(fileContents)
val gll = Gll.gll(startState, inputGraph)
val gll = Gll.gll(startState, getTokenStream(fileContents))
blackhole.consume(gll.parse())
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions solver/src/main/kotlin/org/ucfs/descriptors/Descriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ open class Descriptor<VertexType>(

return true
}

override fun toString(): String {
return "Descriptor(${rsmState.nonterminal}, inputPosition=$inputPosition)"
}
}


10 changes: 9 additions & 1 deletion solver/src/main/kotlin/org/ucfs/input/IInputGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import org.ucfs.sppf.node.SppfNode
* @param LabelType - type of label on edges in input graph
*/
interface IInputGraph<VertexType, LabelType : ILabel> {
fun log(msg: String) {
// println(msg)
}

/**
* Collection of all vertices in graph
*/
Expand Down Expand Up @@ -123,14 +127,18 @@ interface IInputGraph<VertexType, LabelType : ILabel> {
val inputPosition = descriptor.inputPosition
val terminalEdges = rsmState.terminalEdges
val nonterminalEdges = rsmState.nonterminalEdges

log("\n$descriptor")
for (inputEdge in ctx.input.getEdges(inputPosition)) {
if (inputEdge.label.terminal == null) {
log("Epsilon terminal")
handleTerminalOrEpsilonEdge(descriptor, sppfNode, null, descriptor.rsmState, inputEdge.head, 0)
continue
}
log("Compare terminal: current ${inputEdge.label.terminal}$")
for ((edgeTerminal, targetStates) in terminalEdges) {
log("edgeTerminal ${edgeTerminal}$")
if (inputEdge.label.terminal == edgeTerminal) {
log("EQUALS!")
for (target in targetStates) {
handleTerminalOrEpsilonEdge(descriptor, sppfNode, edgeTerminal, target, inputEdge.head, 0)
}
Expand Down
6 changes: 5 additions & 1 deletion solver/src/main/kotlin/org/ucfs/parser/IGll.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ interface IGll<VertexType, LabelType : ILabel> {
inputPosition: VertexType,
): GssNode<VertexType> {
val newNode =
getOrCreateGssNode(nonterminal, inputPosition, weight = gssNode.minWeightOfLeftPart + (sppfNode?.weight ?: 0))
getOrCreateGssNode(
nonterminal,
inputPosition,
weight = gssNode.minWeightOfLeftPart + (sppfNode?.weight ?: 0)
)

if (newNode.addEdge(rsmState, sppfNode, gssNode)) {
if (ctx.poppedGssNodes.containsKey(newNode)) {
Expand Down

0 comments on commit 7ec7b19

Please sign in to comment.