diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 8276be16b..fc9312f58 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -72,5 +72,10 @@ jobs:
- name: Python tests run from .NET
run: dotnet test --runtime any-${{ matrix.platform }} src/python_tests_runner/
- # TODO: Run perf tests
+ - name: Perf tests
+ if: ${{ matrix.python == '3.8' }}
+ run: |
+ pip install --force --no-deps --target src/perf_tests/baseline/ pythonnet==2.5.2
+ dotnet test --configuration Release --runtime any-${{ matrix.platform }} --logger "console;verbosity=detailed" src/perf_tests/
+
# TODO: Run mono tests on Windows?
diff --git a/.gitignore b/.gitignore
index cdb152157..6159b1b14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/src/runtime/interopNative.cs
+/src/perf_tests/baseline/
# General binaries and Build results
*.dll
diff --git a/src/perf_tests/BaselineComparisonBenchmarkBase.cs b/src/perf_tests/BaselineComparisonBenchmarkBase.cs
index 2388e3982..06adcbc67 100644
--- a/src/perf_tests/BaselineComparisonBenchmarkBase.cs
+++ b/src/perf_tests/BaselineComparisonBenchmarkBase.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Reflection;
@@ -17,8 +18,7 @@ public BaselineComparisonBenchmarkBase()
try {
PythonEngine.Initialize();
Console.WriteLine("Python Initialized");
- if (PythonEngine.BeginAllowThreads() == IntPtr.Zero)
- throw new PythonException();
+ Trace.Assert(PythonEngine.BeginAllowThreads() != IntPtr.Zero);
Console.WriteLine("Threading enabled");
}
catch (Exception e) {
@@ -28,6 +28,11 @@ public BaselineComparisonBenchmarkBase()
}
static BaselineComparisonBenchmarkBase()
+ {
+ SetupRuntimeResolve();
+ }
+
+ public static void SetupRuntimeResolve()
{
string pythonRuntimeDll = Environment.GetEnvironmentVariable(BaselineComparisonConfig.EnvironmentVariableName);
if (string.IsNullOrEmpty(pythonRuntimeDll))
diff --git a/src/perf_tests/BaselineComparisonConfig.cs b/src/perf_tests/BaselineComparisonConfig.cs
index 649bb56fd..3f6766554 100644
--- a/src/perf_tests/BaselineComparisonConfig.cs
+++ b/src/perf_tests/BaselineComparisonConfig.cs
@@ -5,7 +5,8 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
-using BenchmarkDotNet.Horology;
+
+using Perfolizer.Horology;
namespace Python.PerformanceTests
{
diff --git a/src/perf_tests/BenchmarkTests.cs b/src/perf_tests/BenchmarkTests.cs
index 6e0afca69..9e033d11f 100644
--- a/src/perf_tests/BenchmarkTests.cs
+++ b/src/perf_tests/BenchmarkTests.cs
@@ -30,14 +30,14 @@ public void SetUp()
public void ReadInt64Property()
{
double optimisticPerfRatio = GetOptimisticPerfRatio(this.summary.Reports);
- AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 0.57);
+ AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 1.35);
}
[Test]
public void WriteInt64Property()
{
double optimisticPerfRatio = GetOptimisticPerfRatio(this.summary.Reports);
- AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 0.57);
+ AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 1.25);
}
static double GetOptimisticPerfRatio(
diff --git a/src/perf_tests/Python.PerformanceTests.csproj b/src/perf_tests/Python.PerformanceTests.csproj
index 22783e595..bde07ecab 100644
--- a/src/perf_tests/Python.PerformanceTests.csproj
+++ b/src/perf_tests/Python.PerformanceTests.csproj
@@ -3,11 +3,25 @@
net472
false
- x64;x86
+ x64
+ x64
+
-
+
+ PreserveNewest
+
+
+
+
+
+ false
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -17,23 +31,17 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- compile
-
+
-
+
-
-
-
-
+
diff --git a/src/perf_tests/PythonCallingNetBenchmark.cs b/src/perf_tests/PythonCallingNetBenchmark.cs
index ef668a911..d7edd4583 100644
--- a/src/perf_tests/PythonCallingNetBenchmark.cs
+++ b/src/perf_tests/PythonCallingNetBenchmark.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Reflection;
using System.Text;
using BenchmarkDotNet.Attributes;
@@ -17,11 +18,11 @@ public void ReadInt64Property()
{
var locals = new PyDict();
locals.SetItem("a", new NetObject().ToPython());
- PythonEngine.Exec($@"
+ Exec($@"
s = 0
for i in range(50000):
s += a.{nameof(NetObject.LongProperty)}
-", locals: locals.Handle);
+", locals: locals);
}
}
@@ -30,13 +31,24 @@ public void WriteInt64Property() {
using (Py.GIL()) {
var locals = new PyDict();
locals.SetItem("a", new NetObject().ToPython());
- PythonEngine.Exec($@"
+ Exec($@"
s = 0
for i in range(50000):
a.{nameof(NetObject.LongProperty)} += i
-", locals: locals.Handle);
+", locals: locals);
}
}
+
+ static void Exec(string code, PyDict locals)
+ {
+ MethodInfo exec = typeof(PythonEngine).GetMethod(nameof(PythonEngine.Exec));
+ object localsArg = typeof(PyObject).Assembly.GetName().Version.Major >= 3
+ ? locals : locals.Handle;
+ exec.Invoke(null, new[]
+ {
+ code, localsArg, null
+ });
+ }
}
class NetObject
diff --git a/src/perf_tests/baseline/.gitkeep b/src/perf_tests/baseline/.gitkeep
new file mode 100644
index 000000000..e69de29bb