Skip to content

Commit

Permalink
Add PredictionMode (LL, SLL) for comparison, decrease number of terms…
Browse files Browse the repository at this point in the history
… (256 -> 128)
  • Loading branch information
KvanTTT committed Jul 10, 2020
1 parent 40fd417 commit 7758dd9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions AntlrLeftRecursionBenchmark/AntlrLeftRecursionTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using Antlr4.Runtime;
using Antlr4.Runtime.Atn;
using AntlrUtils;
using BenchmarkDotNet.Attributes;

namespace AntlrLeftRecursionBenchmark
{
public class AntlrLeftRecursionTests
{
private const int TermsCount = 256;
private const int TermsCount = 128;
private readonly ConsoleErrorListener errorListener = new ConsoleErrorListener();

private readonly IList<IToken> tokens;
Expand All @@ -29,6 +29,7 @@ private string GenerateData()

// x_0_0 && x_0_1 == x_0_2 + x_0_3 * x_0_4 ^ x_0_5 || x_1_0 && x_1_1 == x_1_2 + x_1_3 * x_1_4 ^ x_1_5 || ... || x_n_0 && x_n_1 == x_n_2 + x_n_3 * x_n_4 ^ x_n_5

//var term = "x_0_0";
var term = "x_0_0 && x_0_1 == x_0_2 + x_0_3 * x_0_4 ^ x_0_5";
//var term = "x_0_0 ^ x_0_1 * x_0_2 + x_0_3 == x_0_4 && x_0_5";

Expand All @@ -44,6 +45,8 @@ private string GenerateData()
return result.ToString();
}

[Params("SLL", "LL")] public string Mode { get; set; } = "SLL";

[Benchmark(Baseline = true)]
public void LeftRecursionTest()
{
Expand All @@ -64,6 +67,7 @@ private LeftRecursionGrammarParser CreateParser()
var tokenStream = new CommonTokenStream(listTokenSource);
var parser = new LeftRecursionGrammarParser(tokenStream);
parser.BuildParseTree = false;
parser.Interpreter.PredictionMode = Mode == "SLL" ? PredictionMode.Sll : PredictionMode.Ll;
parser.AddErrorListener(errorListener);
return parser;
}
Expand Down

0 comments on commit 7758dd9

Please sign in to comment.