-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vs/ | ||
**/bin | ||
**/obj | ||
*.binlog | ||
*.binlog | ||
BenchmarkDotNet.Artifacts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Ancillary.Interop\Ancillary.Interop.csproj" /> | ||
<ProjectReference Include="..\DllImportGenerator\DllImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="..\TestAssets\NativeExports\NativeExports.csproj" /> | ||
<ProjectReference Include="..\TestAssets\SharedTypes\SharedTypes.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Benchmarks | ||
{ | ||
partial class NativeExportsNE | ||
{ | ||
public const string NativeExportsNE_Binary = "Microsoft.Interop.Tests." + nameof(NativeExportsNE); | ||
|
||
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "sumi")] | ||
public static partial int Sum(int a, int b); | ||
|
||
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "sumouti")] | ||
public static partial void Sum(int a, int b, out int c); | ||
|
||
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "sumrefi")] | ||
public static partial void Sum(int a, ref int b); | ||
} | ||
|
||
public class BlittableTypes | ||
{ | ||
[Benchmark] | ||
public int IntByValue() | ||
{ | ||
return NativeExportsNE.Sum(3, 42); | ||
} | ||
|
||
[Benchmark] | ||
public int IntOutByRef() | ||
{ | ||
NativeExportsNE.Sum(3, 42, out int result); | ||
return result; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Environments; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Loggers; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Toolchains; | ||
using BenchmarkDotNet.Toolchains.CsProj; | ||
using BenchmarkDotNet.Toolchains.DotNetCli; | ||
using BenchmarkDotNet.Toolchains.Results; | ||
using System; | ||
|
||
namespace Benchmarks | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var config = DefaultConfig.Instance | ||
.AddJob(GetDefaultJob()) | ||
.AddJob(GetForwarderJob()) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jkoritzinsky
Author
Member
|
||
.AddDiagnoser(MemoryDiagnoser.Default); | ||
|
||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); | ||
} | ||
|
||
private static Job GetDefaultJob() | ||
{ | ||
var settings = NetCoreAppSettings.NetCoreApp50; | ||
|
||
return Job.Default.WithToolchain(new Toolchain(".NET 6.0", | ||
new CsProjGenerator(settings.TargetFrameworkMoniker, settings.CustomDotNetCliPath, settings.PackagesPath, "$(MicrosoftNETCoreAppVersion)"), | ||
new DotNetCliBuilder(settings.TargetFrameworkMoniker, settings.CustomDotNetCliPath, settings.Timeout), | ||
new DotNetCliExecutor(settings.CustomDotNetCliPath))) | ||
.WithId("Generated"); | ||
} | ||
|
||
private static Job GetForwarderJob() | ||
{ | ||
var settings = NetCoreAppSettings.NetCoreApp50; | ||
return Job.Default | ||
.WithToolchain(new Toolchain(".NET 6.0 with Forwarders", | ||
new CsProjGenerator(settings.TargetFrameworkMoniker, settings.CustomDotNetCliPath, settings.PackagesPath, "$(MicrosoftNETCoreAppVersion)"), | ||
new GenerateForwarderBuilder(settings), | ||
new DotNetCliExecutor(settings.CustomDotNetCliPath))) | ||
.WithId("Built-in") | ||
.AsBaseline(); | ||
} | ||
} | ||
|
||
internal class GenerateForwarderBuilder : IBuilder | ||
{ | ||
private TimeSpan Timeout { get; } | ||
|
||
private string TargetFrameworkMoniker { get; } | ||
|
||
private string CustomDotNetCliPath { get; } | ||
|
||
public GenerateForwarderBuilder(NetCoreAppSettings settings) | ||
{ | ||
TargetFrameworkMoniker = settings.TargetFrameworkMoniker; | ||
CustomDotNetCliPath = settings.CustomDotNetCliPath; | ||
Timeout = settings.Timeout; | ||
} | ||
|
||
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger) | ||
=> new DotNetCliCommand( | ||
CustomDotNetCliPath, | ||
"/p:DllImportGenerator_GenerateForwarders=true", | ||
generateResult, | ||
logger, | ||
buildPartition, | ||
Array.Empty<EnvironmentVariable>(), | ||
Timeout) | ||
.RestoreThenBuild(); | ||
} | ||
} |
@jkoritzinsky you need
job.WithArguments(new[] { new MsBuildArgument("/p:SomeProperty=Value") })