-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBenchmarks.cs
More file actions
48 lines (41 loc) · 1.61 KB
/
Copy pathBenchmarks.cs
File metadata and controls
48 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
namespace StringMath.Benchmarks
{
[MemoryDiagnoser(true)]
[SimpleJob(RuntimeMoniker.Net80, warmupCount: 0, iterationCount: 1, launchCount: 1)]
public class Benchmarks
{
[Benchmark]
public void Tokenize()
{
var context = MathContext.Default;
var tokenizer = new Tokenizer("1.23235456576878798 - ((3 + {b}) max .1) ^ sqrt(-999 / 2 * 3 max 5) + !5 - 0.00000000002 / {ahghghh}", context);
Token token;
do
{
token = tokenizer.ReadToken();
}
while (token.Type != TokenType.EndOfCode);
}
[Benchmark]
public void Parse()
{
var context = MathContext.Default;
var tokenizer = new Tokenizer("1.23235456576878798 - ((3 + {b}) max .1) ^ sqrt(-999 / 2 * 3 max 5) + !5 - 0.00000000002 / {ahghghh}", context);
var parser = new Parser(tokenizer, context);
_ = parser.Parse();
}
[Benchmark]
public double Evaluate()
{
return "1.23235456576878798 - ((3 + {b}) max .1) ^ sqrt(-999 / 2 * 3 max 5) + !5 - 0.00000000002 / {ahghghh}".ToMathExpr().Substitute("b", 12989d).Substitute("ahghghh", 12345d).Result;
}
[Benchmark]
public double Compile()
{
var fn = "1.23235456576878798 - ((3 + {b}) max .1) ^ sqrt(-999 / 2 * 3 max 5) + !5 - 0.00000000002 / {ahghghh}".ToMathExpr().Substitute("b", 12989d).Substitute("ahghghh", 12345d).Compile("ahghghh");
return fn(12345d);
}
}
}