Faster deep cloning

前端 未结 9 720
深忆病人
深忆病人 2020-12-02 13:44

Does anyone want a framework/class which allows me to clone by values .Net objects? I\'m only interested with public read/write properties (namely DataContracts), and I don\

9条回答
  •  遥遥无期
    2020-12-02 14:25

    There are a lot of libraries that do this operation. You can see benchmark results here:

    In short words, if you need peformance, do it manually, it really faster. Also, some libraries allows to peform shallow cloning (by the question, it is good variant for you), which is faster. And do not use BinaryFormatter if you need any performance.

    Also, @frakon mentions that Expressions trees have same speed as IL Emit, it is slightly incorrect. Expressions Tree is slightly slower, but it can be used in partially trusted app.

    Manual 13ms

    DeepCloner (IL Emit) 167ms

    DeepCloner (Expressions) 267ms

    CloneExtensions (Expressions) 560ms

    NClone 901ms

    Clone.Behave! 8551ms

    GeorgeCloney 1996ms

    Nuclex.Cloning n/a (Crashed)

    FastDeepCloner 1882ms

    BinaryFormatter 15000ms

提交回复
热议问题