This is an excerpt from: Rock Your Code: Code and App Performance for Microsoft .NET
When the need arises to clone an object, Microsoft recommends cloning an object by serializing it to JSON and deserializing it back into a new instance. I was intrigued to explore how performance varies when dealing with reference types, value types, and record types.
Performance Breakdown
When using JsonSerializer for object cloning, the benchmark results revealed clear differences across type categories. Cloning record types proved to be the most efficient.
- 1.087× faster than cloning reference types
- 1.26× faster than cloning value types
While the differences are relatively small, these findings are noteworthy and provided here for your reference.


Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave
© The information in this article is copywritten and cannot be reproduced in any way without express permission from David McCarter.
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
