Skip to content

Commit

Permalink
Benchmark with BenchmarkDotNet.
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-piccioni committed Mar 14, 2018
1 parent 29f84e5 commit b51860e
Show file tree
Hide file tree
Showing 14 changed files with 354 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="VertexArrays.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions OpenGL.Net.Objects.Test/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
6 changes: 2 additions & 4 deletions OpenGL.Net.Test/Memory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright (C) 2016-2017 Luca Piccioni
// Copyright (C) 2016-2018 Luca Piccioni
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,14 +19,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;

using NUnit.Framework;

namespace OpenGL.Test
{
[TestFixture, Category("Framework")]
internal class MemoryTest
public class MemoryTest
{
[Test]
public void Memory_TestUseSystemCopy()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright (C) 2016-2017 Luca Piccioni
// Copyright (C) 2018 Luca Piccioni
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,46 +19,43 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Columns;
using BenchmarkDotNet.Attributes.Jobs;

namespace OpenGL.Test
{
/// <summary>
/// Attribute for marking benchmark methods.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
class BenchmarkAttribute : Attribute
[ClrJob(true), RankColumn]
public class MemoryBenchmarkCopy
{
#region Constructors

/// <summary>
/// Construct a BenchmarkAttribute.
/// </summary>
/// <param name="name">
/// A <see cref="String"/> that specifies the name of the benchmark.
/// </param>
public BenchmarkAttribute(string name)
[GlobalSetup]
public void Memory_CopyBenchmarkSetup()
{
if (name == null)
throw new ArgumentNullException("name");

Name = name;
_BenchmarkArraySrc = new byte[ushort.MaxValue];
_BenchmarkArrayDst = new byte[ushort.MaxValue];
}

#endregion
private byte[] _BenchmarkArraySrc, _BenchmarkArrayDst;

#region Properties
[Params(4, 16, 256, 512, 4096, 8192)]
public int Memory_CopyBenchmarkParams;

/// <summary>
/// The name of the benchmark.
/// </summary>
public readonly string Name;

/// <summary>
/// Number of repetitions.
/// </summary>
public int Repetitions = 1;
[Benchmark()]
public void Memory_CopyBenchmarkSystem()
{
Memory.UseSystemCopy = true;
using (MemoryLock srcLock = new MemoryLock(_BenchmarkArraySrc)) {
Memory.Copy(_BenchmarkArrayDst, srcLock.Address, (ulong)Memory_CopyBenchmarkParams);
}
}

#endregion
[Benchmark]
public void Memory_CopyBenchmarkManaged()
{
Memory.UseSystemCopy = false;
using (MemoryLock srcLock = new MemoryLock(_BenchmarkArraySrc)) {
Memory.Copy(_BenchmarkArrayDst, srcLock.Address, (ulong)Memory_CopyBenchmarkParams);
}
}
}
}
18 changes: 16 additions & 2 deletions OpenGL.Net.Test/OpenGL.Net.Test_monodroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,24 @@
<HintPath>..\packages\Xamarin.Forms.1.5.0.6447\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.DotNet.PlatformAbstractions, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.DotNet.PlatformAbstractions.1.1.2\lib\netstandard1.3\Microsoft.DotNet.PlatformAbstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyModel, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyModel.1.1.0\lib\netstandard1.6\Microsoft.Extensions.DependencyModel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.PlatformAbstractions.1.0.0\lib\netstandard1.3\Microsoft.Extensions.PlatformAbstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.1\lib\MonoAndroid\nunit.framework.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -147,14 +163,12 @@
<DesignTime>True</DesignTime>
<DependentUpon>Vertex4.tt</DependentUpon>
</Compile>
<None Include="BenchmarkAttribute.cs" />
<Compile Include="DeviceContext.cs" />
<Compile Include="Gl.cs" />
<Compile Include="KhronosVersion.cs" />
<Compile Include="Quaternion.cs" />
<Compile Include="RemovedByFeatureAttribute.cs" />
<Compile Include="RequiredByFeatureAttribute.cs" />
<None Include="TestBaseBenchmark.cs" />
<Compile Include="Gl.VERSION_1_0.cs" />
<Compile Include="Gl.VERSION_1_5.cs" />
<Compile Include="Gl.VERSION_2_0.cs" />
Expand Down
30 changes: 28 additions & 2 deletions OpenGL.Net.Test/OpenGL.Net.Test_net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="BenchmarkDotNet.Core, Version=0.10.13.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
<HintPath>..\packages\BenchmarkDotNet.Core.0.10.13\lib\net46\BenchmarkDotNet.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="BenchmarkDotNet.Toolchains.Roslyn, Version=0.10.13.0, Culture=neutral, PublicKeyToken=aa0ca2f9092cefc4, processorArchitecture=MSIL">
<HintPath>..\packages\BenchmarkDotNet.Toolchains.Roslyn.0.10.13\lib\net46\BenchmarkDotNet.Toolchains.Roslyn.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.DotNet.InternalAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.DotNet.InternalAbstractions.1.0.0\lib\net451\Microsoft.DotNet.InternalAbstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.DotNet.PlatformAbstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.DotNet.PlatformAbstractions.1.1.1\lib\net451\Microsoft.DotNet.PlatformAbstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Registry.4.3.0\lib\net46\Microsoft.Win32.Registry.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.1\lib\net35\nunit.framework.dll</HintPath>
<Private>True</Private>
Expand All @@ -109,7 +137,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>ColorRGBA.tt</DependentUpon>
</Compile>
<Compile Include="BenchmarkAttribute.cs" />
<Compile Include="DeviceContext.cs" />
<Compile Include="DevicePixelFormat.cs" />
<Compile Include="DevicePixelFormatCollection.cs" />
Expand Down Expand Up @@ -149,7 +176,6 @@
<Compile Include="RequiredByFeatureAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="TestBaseBenchmark.cs" />
<Compile Include="TestBaseDevice.cs" />
<Compile Include="TestBaseGL.cs" />
<Compile Include="Vertex2.cs">
Expand Down

0 comments on commit b51860e

Please sign in to comment.