Clone with better performance

前端 未结 8 2294
一整个雨季
一整个雨季 2020-12-14 04:29

I want to create deep copy method and I found 3 ways to execute it

1-deep copy with pass each property 1 by 1

2-using reflection

3-using serializatio

相关标签:
8条回答
  • 2020-12-14 05:00

    I made graph with comparison of the three methods plus an expression trees method.

    For large number of objects is reflection 5x faster and manual code and expression trees are 20x faster than serialization. The best by performance are therefore manual code and expression trees.

    Links to used cloning codes (2.-4. used as an extension method):

    1. Manual: Written manually, no link.
    2. Cloning by Serialization
    3. Cloning by Reflection
    4. Cloning by Expression Trees
    0 讨论(0)
  • 2020-12-14 05:06

    The best for performance is creating the clone in your code. So the way "1".

    0 讨论(0)
提交回复
热议问题