克隆具有更好的性能 [英] Clone with better performance

查看:98
本文介绍了克隆具有更好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建深拷贝的方法,我发现3种方式来执行它。

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

每通导特性1,深层副本1

1-deep copy with pass each property 1 by 1

2,使用反射

3,使用序列

请其中他们是表现最好的明智

please which of them is the best at performance wise

推荐答案

第一个选项,手动深拷贝你的价值观,将是迄今为止最高效的。

The first option, manually deep copying your values, will be the most performant by far.

反射将推出相当多的开销,因为它是(相对)慢来访问数据。

Reflection will introduce quite a bit of overhead, as it is (relatively) slow to access data.

序列化是增加了巨大的成本,因为它系列化数据到临时结构,然后反转设置过程。这是一次非常缓慢。

Serialization is adding a huge cost, as it serializes the data into a temporary structure, then reverses the process to set. This is again, very slow.

唯一的优势,选择2或3的是,其在多个类型的可能更容易实现,且可重复使用。第一个选项为每类手写,但速度更快(在内存占用比3选项更有效,以及)。

The only advantage to option 2 or 3 is that its potentially easier to implement, and reusable across multiple types. The first option has to be hand-written per type, but is much faster (and more efficient in memory usage than option 3, as well).

这篇关于克隆具有更好的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆