-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve init-only fields handling, setup bench
- Loading branch information
Showing
14 changed files
with
679 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<LangVersion>preview</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" /> | ||
<PackageReference Include="DeepCloner" Version="0.10.4" /> | ||
<PackageReference Include="DeepCopier" Version="1.0.4" /> | ||
<PackageReference Include="DeepCopy" Version="1.0.3" /> | ||
<PackageReference Include="DeepCopy.Expression" Version="1.4.2" /> | ||
<PackageReference Include="FastDeepCloner" Version="1.3.6" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FastCloner.Contrib\FastCloner.Contrib.csproj" /> | ||
<ProjectReference Include="..\FastCloner\FastCloner.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Force.DeepCloner; | ||
|
||
namespace FastCloner.Benchmark; | ||
|
||
[RankColumn] | ||
[Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)] | ||
[MemoryDiagnoser] | ||
public class Minimal | ||
{ | ||
private TestObject testData; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
testData = new TestObject | ||
{ | ||
Id = 1, | ||
Name = "Test", | ||
NestedObject = new NestedObject | ||
{ | ||
Value = 42, | ||
Description = "Nested test" | ||
} | ||
}; | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public object? FastCloner() | ||
{ | ||
return global::FastCloner.FastCloner.DeepClone(testData); | ||
} | ||
|
||
[Benchmark] | ||
public object? DeepCopier() | ||
{ | ||
return global::DeepCopier.Copier.Copy(testData); | ||
} | ||
|
||
[Benchmark] | ||
public object? DeepCopy() | ||
{ | ||
return global::DeepCopy.DeepCopier.Copy(testData); | ||
} | ||
|
||
[Benchmark] | ||
public object DeepCopyExpression() | ||
{ | ||
return global::DeepCopy.ObjectCloner.Clone(testData); | ||
} | ||
|
||
[Benchmark] | ||
public object? FastDeepCloner() | ||
{ | ||
return global::FastDeepCloner.DeepCloner.Clone(testData); | ||
} | ||
|
||
[Benchmark] | ||
public object? DeepCloner() | ||
{ | ||
return testData.DeepClone(); | ||
} | ||
|
||
public class TestObject | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public NestedObject NestedObject { get; set; } | ||
} | ||
|
||
public class NestedObject | ||
{ | ||
public int Value { get; set; } | ||
public string Description { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Reports; | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace FastCloner.Benchmark; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// this is used only for package "FastDeepCloner" which is not properly packed; todo: fork it and pack for a fair bench | ||
ManualConfig config = DefaultConfig.Instance | ||
.WithOptions(ConfigOptions.DisableOptimizationsValidator); | ||
|
||
Summary summary = BenchmarkRunner.Run<Minimal>(config); | ||
Console.WriteLine(summary); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
FastCloner.SourceGenerator.Console/FastCloner.SourceGenerator.Console.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<LangVersion>preview</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FastCloner.SourceGenerator\FastCloner.SourceGenerator.csproj" | ||
OutputItemType="Analyzer" | ||
ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace FastCloner.SourceGenerator.Console; | ||
using System; | ||
|
||
class Program | ||
{ | ||
|
||
public class Person | ||
{ | ||
public string Name { get; set; } | ||
public int Age { get; set; } | ||
public List<string> Hobbies { get; set; } | ||
} | ||
|
||
|
||
static void Main(string[] args) | ||
{ | ||
Person person = new Person | ||
{ | ||
Name = "John", | ||
Age = 30, | ||
Hobbies = new List<string> { "Reading", "Gaming" } | ||
}; | ||
|
||
/*var clone = PersonClone.Clone(person); | ||
Console.WriteLine($"Original: {person.Name}, {person.Age}"); | ||
Console.WriteLine($"Clone: {clone.Name}, {clone.Age}");*/ | ||
} | ||
} |
Oops, something went wrong.