R
Random
I have a class I'm using to load and deserialize an xml file. Within the
class I'm using the Stopwatch class to time the deserialization. The first
time through the process takes somewhere in the realm of 4900 milliseconds.
If I repeatedly call the method that does the deserialization, the time
drops a thousandfold to just 4 milliseconds.
What's the reason for this? Code (minus the xml file) is below.
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Diagnostics
Public Class GetMyClass() As MyClass
Dim reader As XmlReader
Dim mycls As MyClass
Dim watch As Stopwatch
Dim ser As XmlSerializer = New XmlSerializer(GetType(MyClass))
reader = (load xml from file code here)
watch = Stopwatch.StartNew()
mycls = CType(ser.Deserialize(reader), MyClass)
watch.Stop()
Console.WriteLine(String.Format("Deserialization of Xml took {0}
milliseconds", watch.ElapsedMilliseconds()))
Console.WriteLine(String.Format("Deserialization of Xml took {0} ticks",
watch.ElapsedTicks()))
reader.Close()
Return mycls
End Class
class I'm using the Stopwatch class to time the deserialization. The first
time through the process takes somewhere in the realm of 4900 milliseconds.
If I repeatedly call the method that does the deserialization, the time
drops a thousandfold to just 4 milliseconds.
What's the reason for this? Code (minus the xml file) is below.
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Diagnostics
Public Class GetMyClass() As MyClass
Dim reader As XmlReader
Dim mycls As MyClass
Dim watch As Stopwatch
Dim ser As XmlSerializer = New XmlSerializer(GetType(MyClass))
reader = (load xml from file code here)
watch = Stopwatch.StartNew()
mycls = CType(ser.Deserialize(reader), MyClass)
watch.Stop()
Console.WriteLine(String.Format("Deserialization of Xml took {0}
milliseconds", watch.ElapsedMilliseconds()))
Console.WriteLine(String.Format("Deserialization of Xml took {0} ticks",
watch.ElapsedTicks()))
reader.Close()
Return mycls
End Class