Skip to content

Commit

Permalink
Benchmark Updated for v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Genius762 committed Nov 30, 2020
1 parent 3a2e222 commit 79af253
Show file tree
Hide file tree
Showing 5 changed files with 2,657 additions and 1,003 deletions.
3 changes: 2 additions & 1 deletion Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>net5.0;net48</TargetFrameworks>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
42 changes: 24 additions & 18 deletions Benchmark/FastNewBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Jobs;
using FastGenericNew;
using System;
#pragma warning disable CA1822 // Member does not access instance data and can be marked as static

namespace Benchmark
{
[StopOnFirstError]
[MemoryDiagnoser]
[DisassemblyDiagnoser]
[BaselineColumn]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
//[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class FastNewBenchmark
{
[Benchmark]
public Example DirectNew() =>
new Example();
public static Func<Example> typeNew;

public static Func<object> typeNewBox;

[GlobalSetup]
public void SetUp()
{
typeNew = TypeNew.GetCreateInstance<Example>(typeof(Example));
typeNewBox = TypeNew.GetCreateInstance(typeof(Example));
}

[Benchmark(Baseline = true)]
public Example FastNewT() =>
Test<Example>.FastNew();
FastNew<Example>.CreateInstance();

[Benchmark]
public Example NewT() =>
Test<Example>.New();
public Example DirectNew() => new();

[Benchmark]
public Example ActivatorCreate() =>
Test<Example>.ActivatorCreate();
}

public static class Test<T> where T : new()
{
public static T FastNew() => FastNew<T>.CreateInstance();
Activator.CreateInstance<Example>();

public static T New() => new T();
[Benchmark]
public Example TypeNewGenericResult() =>
typeNew();

public static T ActivatorCreate() => Activator.CreateInstance<T>();
[Benchmark]
public object TypeNewObjectResult() =>
typeNewBox();
}

public class Example { }
Expand Down
44 changes: 25 additions & 19 deletions Benchmark/FastNewValueTypeBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
using BenchmarkDotNet.Jobs;
using FastGenericNew;
using System;
#pragma warning disable CA1822 // Member does not access instance data and can be marked as static

namespace Benchmark
{
[StopOnFirstError]
[MemoryDiagnoser]
[DisassemblyDiagnoser]
[BaselineColumn]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
[SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
//[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class FastNewValueTypeBenchmark
{
[Benchmark]
public ExampleValueType DirectNew() =>
new ExampleValueType();
public static Func<ExampleValueType> typeNew;

public static Func<object> typeNewBox;

[GlobalSetup]
public void SetUp()
{
typeNew = TypeNew.GetCreateInstance<ExampleValueType>(typeof(ExampleValueType));
typeNewBox = TypeNew.GetCreateInstance(typeof(Example));
}

[Benchmark(Baseline = true)]
public ExampleValueType FastNewT() =>
Test<ExampleValueType>.FastNew();
FastNew<ExampleValueType>.CreateInstance();

[Benchmark]
public ExampleValueType NewT() =>
Test<ExampleValueType>.New();
public ExampleValueType DirectNew() => new();

[Benchmark]
public Example ActivatorCreate() =>
Test<Example>.ActivatorCreate();
}

public static class TestValueType<T> where T : new()
{
public static T FastNew() => FastNew<T>.CreateInstance();
public ExampleValueType ActivatorCreate() =>
Activator.CreateInstance<ExampleValueType>();

public static T New() => new T();
[Benchmark]
public ExampleValueType TypeNewGenericResult() =>
typeNew();

public static T ActivatorCreate() => Activator.CreateInstance<T>();
[Benchmark]
public object TypeNewObjectResult() =>
typeNewBox();
}

public struct ExampleValueType { }
Expand Down
15 changes: 3 additions & 12 deletions Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using System.Reflection;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Running;
using System.Reflection;

namespace Benchmark
{
class Program
{
static void Main()
{
BenchmarkRunner.Run(Assembly.GetCallingAssembly());
}
}
}
BenchmarkRunner.Run(Assembly.GetCallingAssembly());
Loading

0 comments on commit 79af253

Please sign in to comment.