Skip to content

Commit 255be97

Browse files
committed
updated object for unit tests, to reflect more useful situation
1 parent d94fac1 commit 255be97

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

DeepCloner.Tests/PerformanceSpec.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Runtime.InteropServices;
45
using System.Runtime.Serialization.Formatters.Binary;
56

67
using CloneExtensions;
@@ -65,7 +66,7 @@ public void Test_Construct_Variants(bool isSafe)
6566
{
6667
// we cache cloners for type, so, this only variant with separate run
6768
BaseTest.SwitchTo(isSafe);
68-
var c1 = new C1 { V1 = 1 };
69+
var c1 = new C1 { V1 = 1, O = new object(), V2 = "xxx" };
6970
// warm up
7071
for (var i = 0; i < 1000; i++) ManualDeepClone(c1);
7172
for (var i = 0; i < 1000; i++) c1.GetClone();
@@ -76,15 +77,15 @@ public void Test_Construct_Variants(bool isSafe)
7677
var sw = new Stopwatch();
7778
sw.Start();
7879

79-
for (var i = 0; i < 1000000; i++) ManualDeepClone(c1);
80+
for (var i = 0; i < 10000000; i++) ManualDeepClone(c1);
8081
Console.WriteLine("Manual: " + sw.ElapsedMilliseconds);
8182
sw.Restart();
8283

83-
for (var i = 0; i < 1000000; i++) c1.DeepClone();
84+
for (var i = 0; i < 10000000; i++) c1.DeepClone();
8485
Console.WriteLine("Deep: " + sw.ElapsedMilliseconds);
8586
sw.Restart();
8687

87-
for (var i = 0; i < 1000000; i++) c1.GetClone();
88+
for (var i = 0; i < 10000000; i++) c1.GetClone();
8889
Console.WriteLine("Clone Extensions: " + sw.ElapsedMilliseconds);
8990
sw.Restart();
9091

@@ -137,7 +138,7 @@ public void Test_Array_Of_Structs_With_Class()
137138
[Test, Ignore("Manual")]
138139
public void Test_Shallow_Variants()
139140
{
140-
var c1 = new C1();
141+
var c1 = new C1 { V1 = 1, O = new object(), V2 = "xxx" };
141142
// warm up
142143
for (var i = 0; i < 1000; i++) ManualShallowClone(c1);
143144
for (var i = 0; i < 1000; i++) c1.Clone();

DeepCloner.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>DeepCloner</id>
55
<title>DeepCloner</title>
6-
<version>0.9.0</version>
6+
<version>0.9.0.1</version>
77
<authors>force</authors>
88
<owners>force</owners>
99
<licenseUrl>https://github.com/force-net/DeepCloner/blob/develop/LICENSE</licenseUrl>
@@ -15,6 +15,7 @@
1515
Fixed an issue with handling references to arrays
1616
Added support for multidimensional arrays and non-zero-based arrays
1717
Added fallback for non-fulltrust code through expressions
18+
Due build issue, release 0.9.0 was invalid, this is fixed variant
1819
</releaseNotes>
1920
<copyright>Copyright by Force 2016</copyright>
2021
<tags>.NET shallow deep clone</tags>

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Shallow cloning (clone only same object, not objects that object relate to)
4444

4545
## Installation
4646

47-
Trought nuget:
47+
Through nuget:
4848
```
4949
Install-Package DeepCloner
5050
```
@@ -54,7 +54,7 @@ Trought nuget:
5454
You can use deep clone of objects for a lot of situations, e.g.:
5555
* Emulation of external service or _deserialization elimination_ (e.g. in Unit Testing). When code has received object from external source, code can change it (because object for code is *own*).
5656
* ReadOnly object replace. Instead of wrapping your object to readonly object, you can clone object and target code can do anything with it without any restriction.
57-
* Caching. You can cache data locally and want to ensurce that cached object hadntt been changed by other code
57+
* Caching. You can cache data locally and want to ensurce that cached object hadn't been changed by other code
5858

5959
You can use shallow clone as fast, light version of deep clone (if your situation allows that). Main difference between deep and shallow clone in code below:
6060
```
@@ -85,11 +85,11 @@ Tables below, just for information. Simple object with some fields ara cloned mu
8585

8686
Method | Time (in ms) | Comments
8787
---|---|---
88-
Manual | 12 | You should manually realize cloning. It requires a lot of work and can cause copy-paste errors, but it is fastest variant
89-
DeepClone / Unsafe | 196 | This variant is 20 times slower than manual, but clones any object without preparation
90-
DeepClone / Safe | 217 | Safe variant based on on expressions
91-
[CloneExtensions](https://github.com/MarcinJuraszek/CloneExtensions) | 407ms | Implementation of cloning objects on expression trees.
92-
BinaryFormatter | 10000 | Another way of deep object cloning through serializing/deserializing object. Instead of Json serializers - it maintains full graph of serializing objects and also do not call any method for cloning object. But due serious overhead, this variant is very slow
88+
Manual | 13 | You should manually realize cloning. It requires a lot of work and can cause copy-paste errors, but it is fastest variant
89+
DeepClone / Unsafe | 331 | This variant is really slower than manual, but clones any object without preparation
90+
DeepClone / Safe | 411 | Safe variant based on on expressions
91+
[CloneExtensions](https://github.com/MarcinJuraszek/CloneExtensions) | 560 | Implementation of cloning objects on expression trees.
92+
BinaryFormatter | 15000 | Another way of deep object cloning through serializing/deserializing object. Instead of Json serializers - it maintains full graph of serializing objects and also do not call any method for cloning object. But due serious overhead, this variant is very slow
9393

9494
**Shallow cloning**
9595
Shallow cloning is usually faster, because we no need to calculate references and clone additional objects.

0 commit comments

Comments
 (0)