Skip to content

Commit

Permalink
Merge pull request #143 from vigoo/generic-input
Browse files Browse the repository at this point in the history
Generic input
  • Loading branch information
vigoo authored Jan 17, 2023
2 parents cbd220c + 6355717 commit 5ece96c
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ abstract class ParserBenchmark[T] {
val parserz: Parserz.Grammar[Any, Nothing, String, T]

var value: String = _
var valueAsChunk: Chunk[Char] = _

@Setup
def setUp(): Unit = {
value = loadInput()
valueAsChunk = Chunk.fromArray(value.toCharArray)
zioSyntax.parseString("")
}

Expand All @@ -49,6 +51,12 @@ abstract class ParserBenchmark[T] {
zioSyntax.parseString(value, ParserImplementation.Recursive)
}

@Benchmark
def zioParserRecursiveOnChunk(): Either[zio.parser.Parser.ParserError[String], T] = {
import zio.parser._
zioSyntax.parseChunk(valueAsChunk)
}

@Benchmark
def zioParserOpStack(): Either[zio.parser.Parser.ParserError[String], T] = {
import zio.parser._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit
@Fork(value = 1)
class LuceneQueryBenchmark {
var testQuery: String = _
var testQueryChunk: Chunk[Char] = _
var catsParser: CatsLuceneQueryParser = _
var zioParserQuery: Syntax[String, Char, Char, Query] = _
var zioParserStrippedQuery: Syntax[String, Char, Char, Query] = _
Expand All @@ -36,6 +37,7 @@ class LuceneQueryBenchmark {
def setUp(): Unit = {
testQuery =
"status:(active OR pending) AND title:(full text search)^2 AND date:[2012-01-01 TO 2012-12-31] AND (quikc~ brwn~ foks~)"
testQueryChunk = Chunk.fromArray(testQuery.toCharArray)

catsParser = new CatsLuceneQueryParser()
val zioParser = new ZioLuceneQueryParser()
Expand All @@ -55,6 +57,10 @@ class LuceneQueryBenchmark {
def zioParseStrippedRecursive(): Either[ParserError[String], Query] =
zioParserStrippedQuery.parseString(testQuery, ParserImplementation.Recursive)

@Benchmark
def zioParseStrippedRecursiveChunk(): Either[ParserError[String], Query] =
zioParserStrippedQuery.parseChunk(testQueryChunk)

@Benchmark
def zioParseStrippedOpStack(): Either[ParserError[String], Query] =
zioParserStrippedQuery.parseString(testQuery, ParserImplementation.StackSafe)
Expand All @@ -64,19 +70,19 @@ class LuceneQueryBenchmark {
// zioParserStrippedQuery.parseChars(testQueryChunk, ParserImplementation.VM)
}

object LuceneQueryBenchmark extends LuceneQueryBenchmark {
def main(args: Array[String]): Unit = {
setUp()
Debug.printParserTree(zioParserQuery.asParser.optimized)
println("----")
Debug.printParserTree(zioParserStrippedQuery.asParser.optimized)
println(s"ZIO Parser result: ${zioParse()}")
println(s"ZIO Parser stripped result: ${zioParseStrippedRecursive()}")
println(s"ZIO Parser stripped op-stack result: ${zioParseStrippedOpStack()}")
println(s"Cats Parser result: ${catsParse()}")

// val builder = new VMBuilder
// builder.compile(zioParserQuery.asParser.asInstanceOf[ErasedParser])
// println(builder.result())
}
}
//object LuceneQueryBenchmark extends LuceneQueryBenchmark {
// def main(args: Array[String]): Unit = {
// setUp()
// Debug.printParserTree(zioParserQuery.asParser.optimized)
// println("----")
// Debug.printParserTree(zioParserStrippedQuery.asParser.optimized)
// println(s"ZIO Parser result: ${zioParse()}")
// println(s"ZIO Parser stripped result: ${zioParseStrippedRecursive()}")
// println(s"ZIO Parser stripped op-stack result: ${zioParseStrippedOpStack()}")
// println(s"Cats Parser result: ${catsParse()}")
//
//// val builder = new VMBuilder
//// builder.compile(zioParserQuery.asParser.asInstanceOf[ErasedParser])
//// println(builder.result())
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ class CharParserMicroBenchmarks {
repeatWithSep0Syntax.parseString(hellosSep)
}

object CharParserMicroBenchmarks extends CharParserMicroBenchmarks {
def main(args: Array[String]): Unit = {
setUp()
// println(skipAndTransform())
// println(skipAndTransformOrElse())
// println(skipAndTransformRepeat())
// println(skipAndTransformZip())
println(repeatWithSep0().map(_.length))
}
}
//object CharParserMicroBenchmarks extends CharParserMicroBenchmarks {
// def main(args: Array[String]): Unit = {
// setUp()
//// println(skipAndTransform())
//// println(skipAndTransformOrElse())
//// println(skipAndTransformRepeat())
//// println(skipAndTransformZip())
// println(repeatWithSep0().map(_.length))
// }
//}
Loading

0 comments on commit 5ece96c

Please sign in to comment.