diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 4c2ed4c..326a082 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -32,13 +32,13 @@ jobs: node-version: '22' - name: Restore dependencies - run: dotnet restore + run: dotnet restore FastClonerCi.slnf - name: Build - run: dotnet build --no-restore + run: dotnet build FastClonerCi.slnf --no-restore - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test FastClonerCi.slnf --no-build --verbosity normal - name: Update GitHub status check if: always() diff --git a/FastCloner.Benchmark/Dictionary.cs b/FastCloner.Benchmark/Dictionary.cs new file mode 100644 index 0000000..e4618be --- /dev/null +++ b/FastCloner.Benchmark/Dictionary.cs @@ -0,0 +1,77 @@ +using BenchmarkDotNet.Attributes; +using Force.DeepCloner; + +namespace FastCloner.Benchmark; + +[RankColumn] +[Orderer(BenchmarkDotNet.Order.SummaryOrderPolicy.FastestToSlowest)] +[MemoryDiagnoser] +public class DictionaryBenchmark +{ + private Dictionary testData; + + [GlobalSetup] + public void Setup() + { + testData = new Dictionary(); + + for (int i = 0; i < 1000; i++) + { + ComplexKey key = new ComplexKey { Id = i, Name = $"Key{i}" }; + testData.Add(key, $"Value{i}"); + } + } + + [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 ComplexKey +{ + public int Id { get; set; } + public string Name { get; set; } + + public override bool Equals(object obj) + { + if (obj is not ComplexKey other) return false; + return Id == other.Id && Name == other.Name; + } + + public override int GetHashCode() + { + return HashCode.Combine(Id, Name); + } +} \ No newline at end of file diff --git a/FastClonerCi.slnf b/FastClonerCi.slnf new file mode 100644 index 0000000..bf04b54 --- /dev/null +++ b/FastClonerCi.slnf @@ -0,0 +1,11 @@ +{ + "solution": { + "path": "FastCloner.sln", + "projects": [ + "FastCloner\\FastCloner.csproj", + "FastCloner.Tests\\FastCloner.Tests.csproj", + "FastCloner.Contrib\\FastCloner.Contrib.csproj", + "FastCloner.Benchmark\\FastCloner.Benchmark.csproj" + ] + } +}