-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
163 changed files
with
519 additions
and
303 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
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
29 changes: 0 additions & 29 deletions
29
src/NoStringEvaluating.Tests/Helpers/FormulaModelFactory.cs
This file was deleted.
Oops, something went wrong.
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
115 changes: 115 additions & 0 deletions
115
src/NoStringEvaluating.Tests/PerfTests/PerformanceTests.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,115 @@ | ||
using System.Diagnostics; | ||
using NoStringEvaluating.Factories; | ||
using NoStringEvaluating.Functions.Base; | ||
using NoStringEvaluating.Functions.Logic; | ||
using NoStringEvaluating.Functions.Math; | ||
using NoStringEvaluating.Models.Values; | ||
using NoStringEvaluating.Tests.PerfTests.Report; | ||
using NUnit.Framework; | ||
|
||
namespace NoStringEvaluating.Tests.PerfTests; | ||
|
||
[NonParallelizable] | ||
[Category("PerfTests")] | ||
[Explicit("These tests are only run when explicitly specified")] | ||
internal class PerformanceTests | ||
{ | ||
private NoStringEvaluator.Facade _serviceFacade; | ||
private ReportContainer _report; | ||
|
||
[OneTimeSetUp] | ||
public void GlobalSetup() | ||
{ | ||
_report = new(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void GlobalTeardown() | ||
{ | ||
ReportWriter.Write(_report); | ||
} | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
var functions = new IFunction[] | ||
{ | ||
new AddFunction(), | ||
new IfFunction(), | ||
new OrFunction(), | ||
new Func_kov(), | ||
new Func_kovt(), | ||
}; | ||
|
||
_serviceFacade = NoStringEvaluator.CreateFacade(cfg => cfg.WithoutDefaultFunctions().WithFunctions(functions)); | ||
} | ||
|
||
[TestCaseSource(nameof(RunSource))] | ||
public void RunFormula(string formulaName, string formula, IDictionary<string, EvaluatorValue> args, long targetElapsedMilliseconds) | ||
{ | ||
// arrange | ||
var n = 1_000_000; | ||
|
||
var nodes = _serviceFacade.FormulaCache.GetFormulaNodes(formula); | ||
|
||
// act, assert | ||
var res = _serviceFacade.Evaluator.CalcNumber(nodes, args); | ||
|
||
var ela = Stopwatch.StartNew(); | ||
for (var i = 0; i < n; i++) | ||
{ | ||
_ = _serviceFacade.Evaluator.Calc(nodes, args); | ||
} | ||
|
||
ela.Stop(); | ||
|
||
_report.Append(formulaName, res, ela.ElapsedMilliseconds, targetElapsedMilliseconds); | ||
} | ||
|
||
private static IEnumerable<object[]> RunSource() | ||
{ | ||
var args = Enumerable.Range(1, 10).ToDictionary(i => $"Arg{i}", _ => (EvaluatorValue)1.7); | ||
|
||
yield return new object[] { "Formula 1", "3 * 9", args, 250 }; | ||
yield return new object[] { "Formula 2", "3 * 9 / 456 * 32 + 12 / 17 - 3", args, 170 }; | ||
yield return new object[] { "Formula 3", "3 * (9 / 456 * (32 + 12)) / 17 - 3", args, 170 }; | ||
yield return new object[] { "Formula 4", "(2 + 6 - (13 * 24 + 5 / (123 - 364 + 23))) - (2 + 6 - (13 * 24 + 5 / (123 - 364 + 23))) + (2 + 6 - (13 * 24 + 5 / (123 - 364 + 23))) * 345 * ((897 - 323)/ 23)", args, 450 }; | ||
yield return new object[] { "Formula 5", "Arg1 * Arg2 + Arg3 - Arg4", args, 350 }; | ||
yield return new object[] { "Formula 6", "Arg1 * (Arg2 + Arg3) - Arg4 / (Arg5 - Arg6 + 1) + 45 * Arg7 + ((Arg8 * 56 + (12 + Arg9))) - Arg10", args, 580 }; | ||
yield return new object[] { "Formula 7", "add(1; 2; 3)", args, 300 }; | ||
yield return new object[] { "Formula 8", "add(add(5; 1) - add(5; 2; 3))", args, 370 }; | ||
yield return new object[] { "Formula 9", "if(Arg1 > 0; add(56 + 9 / 12 * 123.596; or(78; 9; 5; 2; 4; 5; 8; 7); 45;5); 9) * 24 + 52 -33", args, 830 }; | ||
yield return new object[] { "Formula 10", "kov(1; 2; 3) - kovt(8; 9)", args, 350 }; | ||
} | ||
|
||
public class Func_kov : IFunction | ||
{ | ||
public string Name { get; } = "kov"; | ||
|
||
public bool CanHandleNullArguments { get; } | ||
|
||
public InternalEvaluatorValue Execute(List<InternalEvaluatorValue> args, ValueFactory factory) | ||
{ | ||
var res = 1d; | ||
|
||
for (int i = 0; i < args.Count; i++) | ||
{ | ||
res *= args[i]; | ||
} | ||
|
||
return res; | ||
} | ||
} | ||
|
||
public class Func_kovt : IFunction | ||
{ | ||
public string Name { get; } = "kovt"; | ||
|
||
public bool CanHandleNullArguments { get; } | ||
|
||
public InternalEvaluatorValue Execute(List<InternalEvaluatorValue> args, ValueFactory factory) | ||
{ | ||
return args[0] - args[1]; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/NoStringEvaluating.Tests/PerfTests/Report/ReportContainer.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,11 @@ | ||
namespace NoStringEvaluating.Tests.PerfTests.Report; | ||
|
||
internal class ReportContainer | ||
{ | ||
public List<ReportItem> Items = []; | ||
|
||
public void Append(string formula, double result, long elapsedMilliseconds, long targetElapsedMilliseconds) | ||
{ | ||
Items.Add(new ReportItem(formula, result, elapsedMilliseconds, targetElapsedMilliseconds)); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/NoStringEvaluating.Tests/PerfTests/Report/ReportExtensions.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,37 @@ | ||
using System.Globalization; | ||
using Spectre.Console; | ||
|
||
namespace NoStringEvaluating.Tests.PerfTests.Report; | ||
|
||
internal static class ReportExtensions | ||
{ | ||
public static Table AddRows(this Table table, IEnumerable<ReportItem> items) | ||
{ | ||
foreach (var item in items) | ||
{ | ||
table.AddRow(item); | ||
} | ||
|
||
return table; | ||
} | ||
|
||
public static void AddRow(this Table table, ReportItem value) | ||
{ | ||
table.AddRow( | ||
value.Formula.ToText(), | ||
value.Result.ToText(), | ||
value.ElapsedMilliseconds.ToString().ToText(), | ||
value.TargetElapsedMilliseconds.ToString().ToText(), | ||
value.Attention ? "!".ToText() : string.Empty.ToText()); | ||
} | ||
|
||
public static Text ToText(this double value) | ||
{ | ||
return value.ToString("0.00", CultureInfo.InvariantCulture).ToText(); | ||
} | ||
|
||
public static Text ToText(this string value) | ||
{ | ||
return new Text(value); | ||
} | ||
} |
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,6 @@ | ||
namespace NoStringEvaluating.Tests.PerfTests.Report; | ||
|
||
internal record ReportItem(string Formula, double Result, long ElapsedMilliseconds, long TargetElapsedMilliseconds) | ||
{ | ||
public bool Attention => ElapsedMilliseconds > TargetElapsedMilliseconds; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/NoStringEvaluating.Tests/PerfTests/Report/ReportWriter.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,36 @@ | ||
using NUnit.Framework; | ||
using Spectre.Console; | ||
|
||
namespace NoStringEvaluating.Tests.PerfTests.Report; | ||
|
||
internal class ReportWriter | ||
{ | ||
private const string DIRECTORY = "PerformanceTestsResults"; | ||
private const string FILE_PATH = $"{DIRECTORY}/PerformanceTests.txt"; | ||
|
||
public static void Write(ReportContainer resultsContainer) | ||
{ | ||
if (!Directory.Exists(DIRECTORY)) | ||
{ | ||
Directory.CreateDirectory(DIRECTORY); | ||
} | ||
|
||
using var streamWriter = new StreamWriter(FILE_PATH); | ||
|
||
var table = new Table() | ||
.SquareBorder() | ||
.AddColumns("Formula", "Result", "Elapsed time, ms", "Target elapsed time, ms") | ||
.AddColumn(new TableColumn($"Attention").Centered()) | ||
.AddRows(resultsContainer.Items); | ||
|
||
AnsiConsole.Console.Profile.Width = 100; | ||
|
||
AnsiConsole.Record(); | ||
AnsiConsole.Write(table); | ||
|
||
var text = AnsiConsole.ExportText(); | ||
|
||
TestContext.Progress.WriteLine(text); | ||
streamWriter.WriteLine(text); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...ringEvaluating.Tests/Data/CheckFormula.cs → ...ting.Tests/UnitTests/Data/CheckFormula.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
6 changes: 3 additions & 3 deletions
6
...gEvaluating.Tests/Data/EvaluateBoolean.cs → ...g.Tests/UnitTests/Data/EvaluateBoolean.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
6 changes: 3 additions & 3 deletions
6
...Evaluating.Tests/Data/EvaluateDateTime.cs → ....Tests/UnitTests/Data/EvaluateDateTime.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
6 changes: 3 additions & 3 deletions
6
...ngEvaluating.Tests/Data/EvaluateNumber.cs → ...ng.Tests/UnitTests/Data/EvaluateNumber.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
6 changes: 3 additions & 3 deletions
6
...aluating.Tests/Data/EvaluateNumberList.cs → ...ests/UnitTests/Data/EvaluateNumberList.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
6 changes: 3 additions & 3 deletions
6
...ringEvaluating.Tests/Data/EvaluateWord.cs → ...ting.Tests/UnitTests/Data/EvaluateWord.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
6 changes: 3 additions & 3 deletions
6
...Evaluating.Tests/Data/EvaluateWordList.cs → ....Tests/UnitTests/Data/EvaluateWordList.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
6 changes: 3 additions & 3 deletions
6
...ringEvaluating.Tests/Data/ParseFormula.cs → ...ting.Tests/UnitTests/Data/ParseFormula.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
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
Oops, something went wrong.