Skip to content

Commit 59c4d5c

Browse files
Tests added & minor changes
1 parent 2ec2d38 commit 59c4d5c

8 files changed

Lines changed: 73 additions & 12 deletions

File tree

AngouriMath/AngouriMath.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
<Copyright>Angourisoft</Copyright>
99
<PackageProjectUrl>asc-community.org</PackageProjectUrl>
1010
<RepositoryUrl>https://github.com/Angourisoft/MathS</RepositoryUrl>
11-
<AssemblyVersion>0.0.14.0</AssemblyVersion>
12-
<FileVersion>0.0.14.0</FileVersion>
11+
<AssemblyVersion>0.0.15.0</AssemblyVersion>
12+
<FileVersion>0.0.15.0</FileVersion>
1313
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1414
<PackageLicenseExpression></PackageLicenseExpression>
1515
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
1616
<PackageTags>Math, csharp, derivation, latex, calculator, parse, simplification, compute</PackageTags>
17-
<Version>1.0.14</Version>
17+
<Version>1.0.15</Version>
1818
<PackageIconUrl>https://raw.githubusercontent.com/Angourisoft/MathS/master/icon.png</PackageIconUrl>
1919
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
20-
<Description>Enables to work with formulas built in the code or from a string. Computing, derivating, latex rendering, and many more.</Description>
20+
<Description>Enables to work with formulas built in the code or from a string. Computing, derivating, latex rendering, fast functions, and many more.</Description>
2121
<PackageReleaseNotes>Minor changes</PackageReleaseNotes>
2222
<PackageId>AngouriMath</PackageId>
2323
<Product>AngouriMath</Product>

PerformanceBenchmark/CommonTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace PerformanceBenchmark.Tests
88
{
99
public abstract class CommonTest
1010
{
11-
protected List<Func<Entity>> tests;
11+
protected List<Func<object>> tests;
1212
protected static readonly VariableEntity x = MathS.Var("x");
1313
protected static readonly VariableEntity y = MathS.Var("y");
1414
protected static readonly VariableEntity z = MathS.Var("z");
15-
private static int IterCount { get; } = 1000;
16-
private double Watch(Func<Entity> func)
15+
protected static int IterCount { get; set; } = 1000;
16+
private double Watch(Func<object> func)
1717
{
1818
var stopWatch = new Stopwatch();
1919
stopWatch.Start();
@@ -28,7 +28,7 @@ internal string Evaluate()
2828
foreach (var test in tests)
2929
{
3030
var time = Watch(test);
31-
sb.Append(test().ToString() + " : " + (time * 1000).ToString() + " microseconds");
31+
sb.Append(": " + (time * 1000).ToString() + " microseconds");
3232
sb.Append("\n");
3333
}
3434
return sb.ToString();

PerformanceBenchmark/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ class Program
88
static void Main(string[] args)
99
{
1010
var simTest = new SimplificationTest();
11+
Console.WriteLine("Simplify");
1112
Console.WriteLine(simTest.Evaluate());
12-
var derTest = new SimplificationTest();
13+
var derTest = new DerivationTest();
14+
Console.WriteLine("Derive");
1315
Console.WriteLine(derTest.Evaluate());
16+
var utTest = new SubsTest();
17+
Console.WriteLine("Uncompiled sub");
18+
Console.WriteLine(utTest.Evaluate());
19+
var ctTest = new CompiledFunctionTest();
20+
Console.WriteLine("Compiled sub");
21+
Console.WriteLine(ctTest.Evaluate());
1422
}
1523
}
1624
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using AngouriMath;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace PerformanceBenchmark.Tests
7+
{
8+
public class CompiledFunctionTest : CommonTest
9+
{
10+
private List<FastExpression> exprs = new List<FastExpression> {
11+
x.Compile(x),
12+
(MathS.Cos(x) * MathS.Sin(x)).Compile(x),
13+
(MathS.Sqr(MathS.Sin(x + 2 * x)) + MathS.Sqr(MathS.Cos(x + 2 * x))).Compile(x),
14+
(x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))
15+
* x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))
16+
* x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))
17+
* x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))).Compile(x)
18+
};
19+
public CompiledFunctionTest()
20+
{
21+
IterCount = 20000;
22+
tests = new List<Func<object>>();
23+
foreach (var expr in exprs)
24+
tests.Add(() => expr.Call(3));
25+
}
26+
}
27+
}

PerformanceBenchmark/Tests/DerivationTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class DerivationTest : CommonTest
99
{
1010
public DerivationTest()
1111
{
12-
tests = new List<Func<Entity>> {
12+
IterCount = 2000;
13+
tests = new List<Func<object>> {
1314
() => x.Derive(x),
1415
() => (MathS.Cos(x) * MathS.Sin(x)).Derive(x),
1516
() => (MathS.Sqr(MathS.Sin(x + 2 * y)) + MathS.Sqr(MathS.Cos(x + 2 * y))).Derive(x),

PerformanceBenchmark/Tests/SimplificationTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class SimplificationTest : CommonTest
99
{
1010
public SimplificationTest()
1111
{
12-
tests = new List<Func<Entity>> {
12+
IterCount = 300;
13+
tests = new List<Func<object>> {
1314
() => (x * MathS.Sin(x)).Simplify(),
1415
() => (MathS.Cos(x) * MathS.Sin(x)).Simplify(),
1516
() => (MathS.Sqr(MathS.Sin(x + 2 * y)) + MathS.Sqr(MathS.Cos(x + 2 * y))).Simplify(),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using AngouriMath;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace PerformanceBenchmark.Tests
7+
{
8+
public class SubsTest : CommonTest
9+
{
10+
public SubsTest()
11+
{
12+
IterCount = 1000;
13+
tests = new List<Func<object>> {
14+
() => (x * MathS.Sin(x)).Substitute(x, 3).Eval(),
15+
() => (MathS.Cos(x) * MathS.Sin(x)).Substitute(x, 3).Eval(),
16+
() => (MathS.Sqr(MathS.Sin(x + 2 * x)) + MathS.Sqr(MathS.Cos(x + 2 * x))).Substitute(x, 3).Eval(),
17+
() => (x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))
18+
* x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))
19+
* x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))
20+
* x * MathS.Cos(x) / MathS.Sin(MathS.Sqrt(x / MathS.Ln(x)))).Substitute(x, 3).Eval()
21+
};
22+
}
23+
}
24+
}

UnitTests/Common/PerformanceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public long Measure(Func<object> func)
2424
[TestMethod]
2525
public void Test2() => Assert.IsTrue(Measure(() => MathS.FromString("x + log(2, 4)^2 * sin(cos(sin(cos(5)))) + x^3")) < 10);
2626
[TestMethod]
27-
public void Test3() => Assert.IsTrue(Measure(() => (x.Pow(3) + x.Pow(2) - 4 * x - 4).SolveNt(x, precision: 400)) < 220);
27+
public void Test3() => Assert.IsTrue(Measure(() => (x.Pow(3) + x.Pow(2) - 4 * x - 4).SolveNt(x, precision: 400)) < 85);
2828
[TestMethod]
2929
public void Test4() => Assert.IsTrue(Measure(() => x / x) < 1);
3030
[TestMethod]

0 commit comments

Comments
 (0)