| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,5 +72,10 @@ jobs: | |||
| 72 | 72 | - name: Python tests run from .NET | |
| 73 | 73 | run: dotnet test --runtime any-${{ matrix.platform }} src/python_tests_runner/ | |
| 74 | 74 | ||
| 75 | - # TODO: Run perf tests | ||
| 75 | + - name: Perf tests | ||
| 76 | + if: ${{ matrix.python == '3.8' }} | ||
| 77 | + run: | | ||
| 78 | + pip install --force --no-deps --target src/perf_tests/baseline/ pythonnet==2.5.2 | ||
| 79 | + dotnet test --configuration Release --runtime any-${{ matrix.platform }} --logger "console;verbosity=detailed" src/perf_tests/ | ||
| 80 | + | ||
| 76 | 81 | # TODO: Run mono tests on Windows? | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | /src/runtime/interopNative.cs | |
| 2 | + /src/perf_tests/baseline/ | ||
| 2 | 3 | ||
| 3 | 4 | # General binaries and Build results | |
| 4 | 5 | *.dll | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Collections.Generic; | |
| 3 | + using System.Diagnostics; | ||
| 3 | 4 | using System.Linq; | |
| 4 | 5 | using System.Reflection; | |
| 5 | 6 | ||
@@ -17,8 +18,7 @@ public BaselineComparisonBenchmarkBase() | |||
| 17 | 18 | try { | |
| 18 | 19 | PythonEngine.Initialize(); | |
| 19 | 20 | Console.WriteLine("Python Initialized"); | |
| 20 | - if (PythonEngine.BeginAllowThreads() == IntPtr.Zero) | ||
| 21 | - throw new PythonException(); | ||
| 21 | + Trace.Assert(PythonEngine.BeginAllowThreads() != IntPtr.Zero); | ||
| 22 | 22 | Console.WriteLine("Threading enabled"); | |
| 23 | 23 | } | |
| 24 | 24 | catch (Exception e) { | |
@@ -28,6 +28,11 @@ public BaselineComparisonBenchmarkBase() | |||
| 28 | 28 | } | |
| 29 | 29 | ||
| 30 | 30 | static BaselineComparisonBenchmarkBase() | |
| 31 | + { | ||
| 32 | + SetupRuntimeResolve(); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public static void SetupRuntimeResolve() | ||
| 31 | 36 | { | |
| 32 | 37 | string pythonRuntimeDll = Environment.GetEnvironmentVariable(BaselineComparisonConfig.EnvironmentVariableName); | |
| 33 | 38 | if (string.IsNullOrEmpty(pythonRuntimeDll)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | 6 | using BenchmarkDotNet.Configs; | |
| 7 | 7 | using BenchmarkDotNet.Jobs; | |
| 8 | - using BenchmarkDotNet.Horology; | ||
| 8 | + | ||
| 9 | + using Perfolizer.Horology; | ||
| 9 | 10 | ||
| 10 | 11 | namespace Python.PerformanceTests | |
| 11 | 12 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,14 +30,14 @@ public void SetUp() | |||
| 30 | 30 | public void ReadInt64Property() | |
| 31 | 31 | { | |
| 32 | 32 | double optimisticPerfRatio = GetOptimisticPerfRatio(this.summary.Reports); | |
| 33 | - AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 0.57); | ||
| 33 | + AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 1.35); | ||
| 34 | 34 | } | |
| 35 | 35 | ||
| 36 | 36 | [Test] | |
| 37 | 37 | public void WriteInt64Property() | |
| 38 | 38 | { | |
| 39 | 39 | double optimisticPerfRatio = GetOptimisticPerfRatio(this.summary.Reports); | |
| 40 | - AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 0.57); | ||
| 40 | + AssertPerformanceIsBetterOrSame(optimisticPerfRatio, target: 1.25); | ||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | static double GetOptimisticPerfRatio( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,11 +3,25 @@ | |||
| 3 | 3 | <PropertyGroup> | |
| 4 | 4 | <TargetFramework>net472</TargetFramework> | |
| 5 | 5 | <IsPackable>false</IsPackable> | |
| 6 | - <Platforms>x64;x86</Platforms> | ||
| 6 | + <Platforms>x64</Platforms> | ||
| 7 | + <PlatformTarget>x64</PlatformTarget> | ||
| 8 | + | ||
| 7 | 9 | </PropertyGroup> | |
| 8 | 10 | ||
| 9 | 11 | <ItemGroup> | |
| 10 | - <PackageReference Include="BenchmarkDotNet" Version="0.12.0" /> | ||
| 12 | + <Content Include="baseline\Python.Runtime.dll"> | ||
| 13 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| 14 | + </Content> | ||
| 15 | + </ItemGroup> | ||
| 16 | + | ||
| 17 | + <ItemGroup> | ||
| 18 | + <Reference Include="baseline/Python.Runtime.dll"> | ||
| 19 | + <Private>false</Private> | ||
| 20 | + </Reference> | ||
| 21 | + </ItemGroup> | ||
| 22 | + | ||
| 23 | + <ItemGroup> | ||
| 24 | + <PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | ||
| 11 | 25 | <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0"> | |
| 12 | 26 | <PrivateAssets>all</PrivateAssets> | |
| 13 | 27 | <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
@@ -17,23 +31,17 @@ | |||
| 17 | 31 | <PrivateAssets>all</PrivateAssets> | |
| 18 | 32 | <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
| 19 | 33 | </PackageReference> | |
| 20 | - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
| 21 | - <PackageReference Include="pythonnet" Version="2.3.0" GeneratePathProperty="true"> | ||
| 22 | - <IncludeAssets>compile</IncludeAssets> | ||
| 23 | - </PackageReference> | ||
| 34 | + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> | ||
| 24 | 35 | </ItemGroup> | |
| 25 | 36 | ||
| 26 | 37 | <Target Name="GetRuntimeLibBuildOutput" BeforeTargets="Build"> | |
| 27 | - <MSBuild Projects="..\runtime\Python.Runtime.csproj" Properties="PYTHONNET_PY3_VERSION=PYTHON38;Python3Version=PYTHON38;OutputPath=bin\for_perf\"> | ||
| 38 | + <MSBuild Projects="..\runtime\Python.Runtime.csproj" Properties="OutputPath=bin\for_perf\;Configuration=Release;TargetFramework=netstandard2.0" Targets="Build"> | ||
| 28 | 39 | <Output TaskParameter="TargetOutputs" ItemName="NewPythonRuntime" /> | |
| 29 | 40 | </MSBuild> | |
| 30 | 41 | </Target> | |
| 31 | 42 | ||
| 32 | - <Target Name="CopyBaseline" AfterTargets="Build"> | ||
| 33 | - <Copy SourceFiles="$(Pkgpythonnet)\lib\net40\Python.Runtime.dll" DestinationFolder="$(OutDir)\baseline" /> | ||
| 34 | - </Target> | ||
| 35 | - | ||
| 36 | 43 | <Target Name="CopyNewBuild" AfterTargets="Build"> | |
| 44 | + <Message Text="Outputs: @(NewPythonRuntime)" Importance="high" /> | ||
| 37 | 45 | <Copy SourceFiles="@(NewPythonRuntime)" DestinationFolder="$(OutDir)\new" /> | |
| 38 | 46 | </Target> | |
| 39 | 47 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Collections.Generic; | |
| 3 | + using System.Reflection; | ||
| 3 | 4 | using System.Text; | |
| 4 | 5 | ||
| 5 | 6 | using BenchmarkDotNet.Attributes; | |
@@ -17,11 +18,11 @@ public void ReadInt64Property() | |||
| 17 | 18 | { | |
| 18 | 19 | var locals = new PyDict(); | |
| 19 | 20 | locals.SetItem("a", new NetObject().ToPython()); | |
| 20 | - PythonEngine.Exec($@" | ||
| 21 | + Exec($@" | ||
| 21 | 22 | s = 0 | |
| 22 | 23 | for i in range(50000): | |
| 23 | 24 | s += a.{nameof(NetObject.LongProperty)} | |
| 24 | - ", locals: locals.Handle); | ||
| 25 | + ", locals: locals); | ||
| 25 | 26 | } | |
| 26 | 27 | } | |
| 27 | 28 | ||
@@ -30,13 +31,24 @@ public void WriteInt64Property() { | |||
| 30 | 31 | using (Py.GIL()) { | |
| 31 | 32 | var locals = new PyDict(); | |
| 32 | 33 | locals.SetItem("a", new NetObject().ToPython()); | |
| 33 | - PythonEngine.Exec($@" | ||
| 34 | + Exec($@" | ||
| 34 | 35 | s = 0 | |
| 35 | 36 | for i in range(50000): | |
| 36 | 37 | a.{nameof(NetObject.LongProperty)} += i | |
| 37 | - ", locals: locals.Handle); | ||
| 38 | + ", locals: locals); | ||
| 38 | 39 | } | |
| 39 | 40 | } | |
| 41 | + | ||
| 42 | + static void Exec(string code, PyDict locals) | ||
| 43 | + { | ||
| 44 | + MethodInfo exec = typeof(PythonEngine).GetMethod(nameof(PythonEngine.Exec)); | ||
| 45 | + object localsArg = typeof(PyObject).Assembly.GetName().Version.Major >= 3 | ||
| 46 | + ? locals : locals.Handle; | ||
| 47 | + exec.Invoke(null, new[] | ||
| 48 | + { | ||
| 49 | + code, localsArg, null | ||
| 50 | + }); | ||
| 51 | + } | ||
| 40 | 52 | } | |
| 41 | 53 | ||
| 42 | 54 | class NetObject | |
| Back | FazBrowse Home | New Git URL |
0 commit comments