' *********************************************************
''' FIRST BLOCK
Imports
System.
Collections.
Specialized
Imports
System.
Text.
RegularExpressions
Imports
System.
Text
Imports
System.
Threading
Public Class MainForm
Private _str
As StringCollection
Private _sw
As New Stopwatch
Private _intRegex
As Regex
Private _floatRegex
As Regex
Private Sub MainForm_Load
(ByVal sender
As System.
Object, ByVal e
As System.
EventArgs) Handles MyBase.
Load
WebBrowser1.
DocumentText =
"This application demonstrates the difference between <b><code>Parse TryParse
Char Arrays
Regex
TryParse
Int32
Decimal
Single
Double
)
If useParse Then parseTime = DoubleParseRoutine()
If useTryParse Then tryParseTime = DoubleTryParseRoutine()
If useCharArray Then
If useOptimizedCharArray Then
charArrayParseTime = OptimizedDoubleCharArrayRoutine()
Else
charArrayParseTime = DoubleCharArrayRoutine()
End If
End If
If useRegex Then regexParseTime = DoubleRegexRoutine()
sb.Append(TimeResult(parseTime, tryParseTime, charArrayParseTime, regexParseTime))
sb.Append("")
WebBrowser1.DocumentText = sb.ToString
Cursor = Cursors.Arrow
End Sub
Private Function TimeResult(ByVal parseTime As Long, ByVal tryParseTime As Long, ByVal charArrayParseTime As Long, ByVal regexParseTime As Long) As String
Return "
" & parseTime & " ms | " & tryParseTime & "ms | " & charArrayParseTime & "ms | " & regexParseTime & "ms"
End Function
Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
Me.Close()
End Sub
End Class
' ************************************************************
''' SECOND BLOCK
_
Partial Public Class MainForm
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
_
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
_
Private Sub InitializeComponent()
Me.CloseButton = New System.Windows.Forms.Button
Me.RunButton = New System.Windows.Forms.Button
Me.SuccessRateNumericUpDown = New System.Windows.Forms.NumericUpDown
Me.WebBrowser1 = New System.Windows.Forms.WebBrowser
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.StringCountNumericUpDown = New System.Windows.Forms.NumericUpDown
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.IntegerRegexTextBox = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.FloatRegexTextBox = New System.Windows.Forms.TextBox
Me.UseTryCheckBox = New System.Windows.Forms.CheckBox
Me.UseTryParseCheckBox = New System.Windows.Forms.CheckBox
Me.UseCharArrayCheckBox = New System.Windows.Forms.CheckBox
Me.UseRegexCheckBox = New System.Windows.Forms.CheckBox
Me.UseOptimizeCharArrayCheckBox = New System.Windows.Forms.CheckBox
CType(Me.SuccessRateNumericUpDown, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StringCountNumericUpDown, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'CloseButton
'
Me.CloseButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.CloseButton.Location = New System.Drawing.Point(592, 441)
Me.CloseButton.Margin = New System.Windows.Forms.Padding(4)
Me.CloseButton.Name = "CloseButton"
Me.CloseButton.Size = New System.Drawing.Size(100, 28)
Me.CloseButton.TabIndex = 0
Me.CloseButton.Text = "Close"
'
'RunButton
'
Me.RunButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.RunButton.Location = New System.Drawing.Point(484, 441)
Me.RunButton.Margin = New System.Windows.Forms.Padding(4)
Me.RunButton.Name = "RunButton"
Me.RunButton.Size = New System.Drawing.Size(100, 28)
Me.RunButton.TabIndex = 1
Me.RunButton.Text = "Run"
'
'SuccessRateNumericUpDown
'
Me.SuccessRateNumericUpDown.Location = New System.Drawing.Point(461, 15)
Me.SuccessRateNumericUpDown.Margin = New System.Windows.Forms.Padding(4)
Me.SuccessRateNumericUpDown.Name = "SuccessRateNumericUpDown"
Me.SuccessRateNumericUpDown.Size = New System.Drawing.Size(77, 22)
Me.SuccessRateNumericUpDown.TabIndex = 5
Me.SuccessRateNumericUpDown.Value = New Decimal(New Integer() {100, 0, 0, 0})
'
'WebBrowser1
'
Me.WebBrowser1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.WebBrowser1.Location = New System.Drawing.Point(17, 108)
Me.WebBrowser1.Margin = New System.Windows.Forms.Padding(4)
Me.WebBrowser1.Name = "WebBrowser1"
Me.WebBrowser1.Size = New System.Drawing.Size(675, 325)
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(547, 17)
Me.Label2.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(49, 16)
Me.Label2.TabIndex = 10
Me.Label2.Text = "percent"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(16, 17)
Me.Label3.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(110, 16)
Me.Label3.TabIndex = 11
Me.Label3.Text = "Attempt to convert"
'
'StringCountNumericUpDown
'
Me.StringCountNumericUpDown.Location = New System.Drawing.Point(144, 15)
Me.StringCountNumericUpDown.Margin = New System.Windows.Forms.Padding(4)
Me.StringCountNumericUpDown.Maximum = New Decimal(New Integer() {999999, 0, 0, 0})
Me.StringCountNumericUpDown.Minimum = New Decimal(New Integer() {1, 0, 0, 0})
Me.StringCountNumericUpDown.Name = "StringCountNumericUpDown"
Me.StringCountNumericUpDown.Size = New System.Drawing.Size(77, 22)
Me.StringCountNumericUpDown.TabIndex = 12
Me.StringCountNumericUpDown.Value = New Decimal(New Integer() {10000, 0, 0, 0})
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(219, 16)
Me.Label5.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(0, 0)
Me.Label5.TabIndex = 13
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(229, 17)
Me.Label6.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(208, 16)
Me.Label6.TabIndex = 14
Me.Label6.Text = "string values with a success rate of"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(18, 47)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(88, 16)
Me.Label1.TabIndex = 16
Me.Label1.Text = "Integer Regex"
'
'IntegerRegexTextBox
'
Me.IntegerRegexTextBox.Location = New System.Drawing.Point(112, 44)
Me.IntegerRegexTextBox.Name = "IntegerRegexTextBox"
Me.IntegerRegexTextBox.Size = New System.Drawing.Size(210, 23)
Me.IntegerRegexTextBox.TabIndex = 17
Me.IntegerRegexTextBox.Text = "^([-+]?\d+)$"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(397, 47)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(77, 16)
Me.Label4.TabIndex = 18
Me.Label4.Text = "Float Regex"
'
'FloatRegexTextBox
'
Me.FloatRegexTextBox.Location = New System.Drawing.Point(480, 44)
Me.FloatRegexTextBox.Name = "FloatRegexTextBox"
Me.FloatRegexTextBox.Size = New System.Drawing.Size(212, 23)
Me.FloatRegexTextBox.TabIndex = 19
Me.FloatRegexTextBox.Text = "^([-+]?\d+\.?\d*)$"
'
'UseTryCheckBox
'
Me.UseTryCheckBox.AutoSize = True
Me.UseTryCheckBox.Checked = True
Me.UseTryCheckBox.CheckState = System.Windows.Forms.CheckState.Checked
Me.UseTryCheckBox.Location = New System.Drawing.Point(18, 81)
Me.UseTryCheckBox.Name = "UseTryCheckBox"
Me.UseTryCheckBox.Size = New System.Drawing.Size(87, 20)
Me.UseTryCheckBox.TabIndex = 21
Me.UseTryCheckBox.Text = "Use Parse"
'
'UseTryParseCheckBox
'
Me.UseTryParseCheckBox.AutoSize = True
Me.UseTryParseCheckBox.Checked = True
Me.UseTryParseCheckBox.CheckState = System.Windows.Forms.CheckState.Checked
Me.UseTryParseCheckBox.Location = New System.Drawing.Point(109, 81)
Me.UseTryParseCheckBox.Name = "UseTryParseCheckBox"
Me.UseTryParseCheckBox.Size = New System.Drawing.Size(110, 20)
Me.UseTryParseCheckBox.TabIndex = 22
Me.UseTryParseCheckBox.Text = "Use Try Parse"
'
'UseCharArrayCheckBox
'
Me.UseCharArrayCheckBox.AutoSize = True
Me.UseCharArrayCheckBox.Checked = True
Me.UseCharArrayCheckBox.CheckState = System.Windows.Forms.CheckState.Checked
Me.UseCharArrayCheckBox.Location = New System.Drawing.Point(225, 80)
Me.UseCharArrayCheckBox.Name = "UseCharArrayCheckBox"
Me.UseCharArrayCheckBox.Size = New System.Drawing.Size(114, 20)
Me.UseCharArrayCheckBox.TabIndex = 23
Me.UseCharArrayCheckBox.Text = "Use Char Array"
'
'UseRegexCheckBox
'
Me.UseRegexCheckBox.AutoSize = True
Me.UseRegexCheckBox.Checked = True
Me.UseRegexCheckBox.CheckState = System.Windows.Forms.CheckState.Checked
Me.UseRegexCheckBox.Location = New System.Drawing.Point(345, 80)
Me.UseRegexCheckBox.Name = "UseRegexCheckBox"
Me.UseRegexCheckBox.Size = New System.Drawing.Size(91, 20)
Me.UseRegexCheckBox.TabIndex = 24
Me.UseRegexCheckBox.Text = "Use Regex"
'
'UseOptimizeCharArrayCheckBox
'
Me.UseOptimizeCharArrayCheckBox.AccessibleRole = System.Windows.Forms.AccessibleRole.None
Me.UseOptimizeCharArrayCheckBox.AutoSize = True
Me.UseOptimizeCharArrayCheckBox.Location = New System.Drawing.Point(551, 81)
Me.UseOptimizeCharArrayCheckBox.Name = "UseOptimizeCharArrayCheckBox"
Me.UseOptimizeCharArrayCheckBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes
Me.UseOptimizeCharArrayCheckBox.Size = New System.Drawing.Size(141, 20)
Me.UseOptimizeCharArrayCheckBox.TabIndex = 26
Me.UseOptimizeCharArrayCheckBox.Text = "Optimize Char Array"
'
'MainForm
'
Me.AcceptButton = Me.RunButton
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.CloseButton
Me.ClientSize = New System.Drawing.Size(708, 476)
Me.Controls.Add(Me.UseOptimizeCharArrayCheckBox)
Me.Controls.Add(Me.UseRegexCheckBox)
Me.Controls.Add(Me.UseCharArrayCheckBox)
Me.Controls.Add(Me.UseTryParseCheckBox)
Me.Controls.Add(Me.UseTryCheckBox)
Me.Controls.Add(Me.FloatRegexTextBox)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.IntegerRegexTextBox)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.StringCountNumericUpDown)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.WebBrowser1)
Me.Controls.Add(Me.SuccessRateNumericUpDown)
Me.Controls.Add(Me.RunButton)
Me.Controls.Add(Me.CloseButton)
Me.Margin = New System.Windows.Forms.Padding(4)
Me.Name = "MainForm"
Me.Text = "TryParse Benchmark"
CType(Me.SuccessRateNumericUpDown, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StringCountNumericUpDown, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents CloseButton As System.Windows.Forms.Button
Friend WithEvents RunButton As System.Windows.Forms.Button
Friend WithEvents SuccessRateNumericUpDown As System.Windows.Forms.NumericUpDown
Friend WithEvents WebBrowser1 As System.Windows.Forms.WebBrowser
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents StringCountNumericUpDown As System.Windows.Forms.NumericUpDown
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents IntegerRegexTextBox As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents FloatRegexTextBox As System.Windows.Forms.TextBox
Friend WithEvents UseTryCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents UseTryParseCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents UseCharArrayCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents UseRegexCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents UseOptimizeCharArrayCheckBox As System.Windows.Forms.CheckBox
End Class
Comments
Voting
|
There are currently no comments for this snippet.