we use the following code to deep copy an Element obj, the code will be executed thousands of times(copy thousands of different Elements), it takes us a lot of time(about 1 minute )
public static Element Clone(Element me)
{
MemoryStream stream = new MemoryStream();
try
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, me);
stream.Seek(0, SeekOrigin.Begin);
return (Element)formatter.Deserialize(stream);
}
finally
{
stream.Close();
}
}
How can we improve the performance ?