-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from b3b00/technical/memory-profiling
Technical/memory profiling
- Loading branch information
Showing
26 changed files
with
464 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Toolchains.CsProj; | ||
using expressionparser; | ||
using simpleExpressionParser; | ||
using sly.parser; | ||
using sly.parser.generator; | ||
using ExpressionToken = simpleExpressionParser.ExpressionToken; | ||
|
||
namespace benchCurrent | ||
{ | ||
|
||
[MemoryDiagnoser] | ||
|
||
[Config(typeof(Config))] | ||
public class SimpleExpressionBench | ||
{ | ||
|
||
|
||
private class Config : ManualConfig | ||
{ | ||
public Config() | ||
{ | ||
var baseJob = Job.MediumRun.With(CsProjCoreToolchain.NetCoreApp70); | ||
} | ||
} | ||
|
||
private Parser<ExpressionToken, double> BenchedParser; | ||
private Parser<GenericExpressionToken, double> BenchedGenericParser; | ||
|
||
private string content = ""; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
Console.WriteLine(("SETUP")); | ||
content = "1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20"; | ||
|
||
SimpleExpressionParser p = new SimpleExpressionParser(); | ||
var builder = new ParserBuilder<ExpressionToken, double>(); | ||
|
||
var result = builder.BuildParser(p, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); | ||
|
||
if (result.IsError) | ||
{ | ||
result.Errors.ForEach(x => Console.WriteLine(x.Message)); | ||
Environment.Exit(1); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("parser ok"); | ||
BenchedParser = result.Result; | ||
} | ||
|
||
GenericSimpleExpressionParser gp = new GenericSimpleExpressionParser(); | ||
var genericbuilder = new ParserBuilder<GenericExpressionToken, double>(); | ||
|
||
var genericresult = genericbuilder.BuildParser(gp, ParserType.EBNF_LL_RECURSIVE_DESCENT, "root"); | ||
|
||
if (genericresult.IsError) | ||
{ | ||
genericresult.Errors.ForEach(x => Console.WriteLine(x.Message)); | ||
Environment.Exit(2); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("parser ok"); | ||
BenchedGenericParser = genericresult.Result; | ||
} | ||
} | ||
|
||
|
||
|
||
[Benchmark] | ||
|
||
public void TestExpressionRegex() | ||
{ | ||
if (BenchedParser == null) | ||
{ | ||
Console.WriteLine("regex parser is null"); | ||
} | ||
else | ||
{ | ||
for (int i = 0; i < 50; i++) | ||
{ | ||
var ignored = BenchedParser.Parse(content); | ||
} | ||
} | ||
} | ||
|
||
// [Benchmark] | ||
|
||
public void TestExpressionGeneric() | ||
{ | ||
if (BenchedGenericParser == null) | ||
{ | ||
Console.WriteLine("generic parser is null"); | ||
} | ||
else | ||
{ | ||
for (int i = 0; i < 50; i++) | ||
{ | ||
var ignored = BenchedGenericParser.Parse(content); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using sly.i18n; | ||
using sly.lexer; | ||
|
||
namespace simpleExpressionParser | ||
{ | ||
public enum ExpressionToken | ||
{ | ||
// float number | ||
[Lexeme("[0-9]+\\.[0-9]+")] DOUBLE = 1, | ||
|
||
// integer | ||
[Lexeme("[0-9]+")] INT = 3, | ||
|
||
[Lexeme("[a-zA-Z]+")] IDENTIFIER = 4, | ||
|
||
// the + operator | ||
[LexemeLabel("en","plus sign")] | ||
[LexemeLabel("fr","plus")] | ||
[Lexeme("\\+")] PLUS = 5, | ||
|
||
// the - operator | ||
[LexemeLabel("en","minus sign")] | ||
[LexemeLabel("fr","moins")] | ||
[Lexeme("\\-")] MINUS = 6, | ||
|
||
// the * operator | ||
[LexemeLabel("en","times sign")] | ||
[LexemeLabel("fr","multiplication")] | ||
[Lexeme("\\*")] TIMES = 7, | ||
|
||
// the / operator | ||
[LexemeLabel("en","divide sign")] | ||
[LexemeLabel("fr","division")] | ||
[Lexeme("\\/")] DIVIDE = 8, | ||
|
||
// a left paranthesis ( | ||
[LexemeLabel("en","opening parenthesis")] | ||
[LexemeLabel("fr","parenthèse ouvrante")] | ||
[Lexeme("\\(")] LPAREN = 9, | ||
|
||
// a right paranthesis ) | ||
[LexemeLabel("en","closing parenthesis")] | ||
[LexemeLabel("fr","parenthèse fermante")] | ||
[Lexeme("\\)")] RPAREN = 10, | ||
|
||
[LexemeLabel("fr","point d'exclamation")] | ||
[LexemeLabel("en","exclamation point")] | ||
[Lexeme("!")] FACTORIAL = 13, | ||
|
||
|
||
// a whitespace | ||
[Lexeme("[ \\t]+", true)] WS = 11, | ||
|
||
[Lexeme("[\\n\\r]+", true, true)] EOL = 12 | ||
|
||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/samples/SimpleExpressionParser/GenericExpressionToken.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using sly.i18n; | ||
using sly.lexer; | ||
|
||
namespace simpleExpressionParser; | ||
|
||
public enum GenericExpressionToken | ||
{ | ||
// float number | ||
[Double] DOUBLE = 1, | ||
|
||
// integer | ||
[Int] INT = 3, | ||
|
||
[AlphaNumId] IDENTIFIER = 4, | ||
|
||
// the + operator | ||
[LexemeLabel("en", "plus sign")] [LexemeLabel("fr", "plus")] | ||
[Sugar("+")] | ||
PLUS = 5, | ||
|
||
// the - operator | ||
[LexemeLabel("en", "minus sign")] [LexemeLabel("fr", "moins")] [Sugar("-")] | ||
MINUS = 6, | ||
|
||
// the * operator | ||
[LexemeLabel("en", "times sign")] [LexemeLabel("fr", "multiplication")] [Sugar("*")] | ||
TIMES = 7, | ||
|
||
// the / operator | ||
[LexemeLabel("en", "divide sign")] [LexemeLabel("fr", "division")] [Sugar("/")] | ||
DIVIDE = 8, | ||
|
||
// a left paranthesis ( | ||
[LexemeLabel("en", "opening parenthesis")] [LexemeLabel("fr", "parenthèse ouvrante")] [Sugar("(")] | ||
LPAREN = 9, | ||
|
||
// a right paranthesis ) | ||
[LexemeLabel("en", "closing parenthesis")] [LexemeLabel("fr", "parenthèse fermante")] [Sugar(")")] | ||
RPAREN = 10, | ||
|
||
[LexemeLabel("fr", "point d'exclamation")] [LexemeLabel("en", "exclamation point")] [Sugar("!")] | ||
FACTORIAL = 13, | ||
|
||
} |
Oops, something went wrong.