Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Aug 28, 2020
1 parent 05d3381 commit 0a0a5bb
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
9 changes: 6 additions & 3 deletions xFunc.Benchmark/Benchmarks/ProcessorBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using BenchmarkDotNet.Attributes;
using xFunc.Maths;
using xFunc.Maths.Expressions;
using xFunc.Maths.Results;

namespace xFunc.Benchmark.Benchmarks
{
Expand All @@ -31,8 +32,10 @@ public void Setup()

[Benchmark]
public IExpression Parse()
{
return processor.Parse("(100.1 + 2(3sin(4cos(5tan(6ctg(10x)))) * 3) / (func(a, b, c) ^ 2)) - (cos(y) - 111.3) & (true | false -> true <-> false eq true) + (det({{1, 2}, {3, 4}}) * 10log(2, 3)) + re(3 + 2i) - im(2 - 9i) + (9 + 2i)");
}
=> processor.Parse("(100.1 + 2(3sin(4cos(5tan(6ctg(10x)))) * 3) / (func(a, b, c) ^ 2)) - (cos(y) - 111.3) & (true | false -> true <-> false eq true) + (det({{1, 2}, {3, 4}}) * 10log(2, 3)) + re(3 + 2i) - im(2 - 9i) + (9 + 2i)");

[Benchmark]
public NumberResult Solve()
=> processor.Solve<NumberResult>("count(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + (2 * sin(4 * cos(6 * tan(8 * cot(pi) ^ 2) ^ 3) ^ 4) ^ 5 + 2 * sin(4 * cos(6 * tan(8 * cot(pi) ^ 2) ^ 3) ^ 4) ^ 5 + 2 * sin(4 * cos(6 * tan(8 * cot(pi) ^ 2) ^ 3) ^ 4) ^ 5 + 2 * sin(4 * cos(6 * tan(8 * cot(pi) ^ 2) ^ 3) ^ 4) ^ 5) * 10 ^ 6 + 10!");
}
}
87 changes: 87 additions & 0 deletions xFunc.Benchmark/Benchmarks/TypeAnalyzerBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2012-2020 Dmytro Kyshchenko
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using BenchmarkDotNet.Attributes;
using xFunc.Maths.Analyzers.TypeAnalyzers;
using xFunc.Maths.Expressions;
using xFunc.Maths.Expressions.Matrices;
using xFunc.Maths.Expressions.Statistical;

namespace xFunc.Benchmark.Benchmarks
{
public class TypeAnalyzerBenchmark
{
private TypeAnalyzer analyzer;

private GCD gcd;
private GCD gcdUndefined;

private Matrix matrix;

private Count count;

[GlobalSetup]
public void Setup()
{
analyzer = new TypeAnalyzer();

gcd = new GCD(new IExpression[]
{
new Number(2), new Number(4), new Number(6), new Number(8),
new Number(2), new Number(4), new Number(6), new Number(8),
new Number(2), new Number(4), new Number(6), new Number(8),
new Number(2), new Number(4), new Number(6), new Number(8),
});
gcdUndefined = new GCD(new IExpression[]
{
new Number(2), new Number(4), new Number(6), new Number(8),
new Number(2), new Number(4), new Number(6), new Number(8),
Variable.X, new Number(4), new Number(6), new Number(8),
new Number(2), new Number(4), new Number(6), new Number(8),
});

matrix = new Matrix(new[]
{
new Vector(new IExpression[] { new Number(2), new Number(2), new Number(2), }),
new Vector(new IExpression[] { new Number(2), new Number(2), new Number(2), }),
new Vector(new IExpression[] { new Number(2), new Number(2), new Number(2), }),
});

count = new Count(new IExpression[]
{
new Number(2), new Number(2), new Number(2), new Number(2),
new Number(2), new Number(2), new Number(2), new Number(2),
new Number(2), new Number(2), new Number(2), new Number(2),
new Number(2), new Number(2), new Number(2), new Number(2),
});
}

[Benchmark]
public ResultType GCD()
=> gcd.Analyze(analyzer);

[Benchmark]
public ResultType GCDUndefined()
=> gcdUndefined.Analyze(analyzer);

[Benchmark]
public ResultType Matrix()
=> matrix.Analyze(analyzer);

[Benchmark]
public ResultType Count()
=> count.Analyze(analyzer);
}
}

0 comments on commit 0a0a5bb

Please sign in to comment.