使用XML序列化程式產生器工具加速XML序列化
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim count As Integer = 1
Dim perosn As New Person
Dim xs As New XmlSerializer(GetType(Person))
Dim sw As Stopwatch = Stopwatch.StartNew
Using ms As New MemoryStream
For i As Integer = 0 To count - 1
ms.Seek(0, SeekOrigin.Begin)
xs.Serialize(ms, perosn)
Next
End Using
MsgBox("ElapsedMilliseconds: " & sw.ElapsedMilliseconds)
End Sub
End Class
Public Class Person Private _name As String Public Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property
Private _year As Integer
Public Property Year() As Integer
Get
Return _year
End Get
Set(ByVal value As Integer)
_year = value
End Set
End Property
End Class
[/silent] [/verbose]
type from the input assembly. Short form is ‘/t:’.
/reference: Reference metadata from the specified assembly files.
Short form is ‘/r:’.
/compiler: Visual C# compiler options to use while compiling generated
code. Short form is ‘/c’.
For complete list of available options see c# compiler help.
/proxytypes Generate serialization code only for proxy classes and web
method parameters. Short form is ‘/p’.
/debug Generate image which can be used under a debugger.
Short form is ‘/d’.
/keep Keep source code and compiler temp files. Short form is ‘/k’.
/force Forces overwrite of a previously generated assembly. Short form is ‘/f’.
<br /></strong> /out: Output directory name (default: target assembly location).
Short form is ‘/o:’.
/parsableerrors
Print errors in a format similar to those reported by
compilers.
/nologo Prevents displaying of logo. Short form is ‘/n’.
/silent Prevents displaying of success messages. Short form is ‘/s’.
/verbose Displays verbose output for debugging. Short form is ‘/v’. List types from the target assembly that cannot be serialized
with XmlSerializer.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim count As Integer = 1000
Dim perosn As New Person
Dim xs As New PersonSerializer
Dim sw As Stopwatch = Stopwatch.StartNew
Using ms As New MemoryStream
For i As Integer = 0 To count - 1
ms.Seek(0, SeekOrigin.Begin)
xs.Serialize(ms, perosn)
Next
End Using
MsgBox("ElapsedMilliseconds: " & sw.ElapsedMilliseconds)
End Sub
End Class
<td valign="top" width="132">無XML序列化組件</td>
<td valign="top" width="150">有XML序列化組件</td>
<td valign="top" width="212">使用XML序列化組件的Serialzer</td>
</tr>
<tr>
<td valign="top" width="79">1000 </td>
<td valign="top" width="132">125 </td>
<td valign="top" width="150">107</td>
<td valign="top" width="212">84</td>
</tr>
<tr>
<td valign="top" width="79">10000 </td>
<td valign="top" width="132">946 </td>
<td valign="top" width="150">884</td>
<td valign="top" width="212">597</td>
</tr>
<tr>
<td valign="top" width="79">100000 </td>
<td valign="top" width="132">7382 </td>
<td valign="top" width="150">5909</td>
<td valign="top" width="212">5924</td>
</tr>
<tr>
<td valign="top" width="79">1000000 </td>
<td valign="top" width="132">62892 </td>
<td valign="top" width="150">59159</td>
<td valign="top" width="212">44779</td>
</tr>