Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e28711

Browse files
committed
implemented PythonCallingNet benchmark test
1 parent 65a4184 commit 2e28711

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/perf_tests/BaselineComparisonConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ public BaselineComparisonConfig()
2020

2121
var baseJob = Job.Default;
2222
this.Add(baseJob
23+
.WithId("baseline")
2324
.WithEnvironmentVariable(EnvironmentVariableName,
2425
Path.Combine(deploymentRoot, "baseline", "Python.Runtime.dll"))
25-
.AsBaseline());
26+
.WithBaseline(true));
2627
this.Add(baseJob
28+
.WithId("new")
2729
.WithEnvironmentVariable(EnvironmentVariableName,
2830
Path.Combine(deploymentRoot, "new", "Python.Runtime.dll")));
2931
}

src/perf_tests/BenchmarkTests.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35
using System.Reflection;
46

7+
using BenchmarkDotNet.Reports;
58
using BenchmarkDotNet.Running;
69
using NUnit.Framework;
710

@@ -19,8 +22,19 @@ public void SetUp()
1922
public void PythonCallingNet()
2023
{
2124
var summary = BenchmarkRunner.Run<PythonCallingNetBenchmark>();
22-
Console.WriteLine(summary);
23-
Assert.Inconclusive();
25+
26+
Assert.IsNotEmpty(summary.Reports);
27+
Assert.IsTrue(summary.Reports.All(r => r.Success));
28+
29+
double optimisticPerfRatio = GetOptimisticPerfRatio(summary.Reports);
30+
Assert.LessOrEqual(optimisticPerfRatio, 1.03);
31+
}
32+
33+
static double GetOptimisticPerfRatio(IReadOnlyList<BenchmarkReport> reports) {
34+
var baseline = reports.Single(r => r.BenchmarkCase.Job.ResolvedId == "baseline").ResultStatistics;
35+
var @new = reports.Single(r => r.BenchmarkCase.Job.ResolvedId != "baseline").ResultStatistics;
36+
double newTimeOptimistic = @new.Mean - (@new.StandardDeviation + baseline.StandardDeviation) * 0.5;
37+
return newTimeOptimistic / baseline.Mean;
2438
}
2539

2640
public static string DeploymentRoot => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

0 commit comments

Comments
 (0)