by Sid (1 Submission)
Category: Miscellaneous
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Wed 6th May 2009
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Application to measure the performance of code fragments. Simply put two pieces of code you want to measure within the methods code1 and code2
Inherits System.Windows.Forms.Form
'by Sider 2009
Private fin As Boolean = False
Const unMillon As Integer = 1000000
Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef lpPerformanceCount As Int64) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef lpFrequency As Int64) As Boolean
Private components As System.ComponentModel.IContainer
Friend WithEvents txtMax1 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents txtMin1 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents txtAvg1 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents txtAvg2 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents txtMin2 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents txtMax2 As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents btnStar As System.Windows.Forms.Button = New System.Windows.Forms.Button
Friend WithEvents pb1 As System.Windows.Forms.ProgressBar = New System.Windows.Forms.ProgressBar
Friend WithEvents btnStop As System.Windows.Forms.Button = New System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents txtRep As System.Windows.Forms.TextBox = New System.Windows.Forms.TextBox
Friend WithEvents Label6 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents lblMINR2 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents lblMAXR2 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents lblMINR1 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Friend WithEvents lblMAXR1 As System.Windows.Forms.Label = New System.Windows.Forms.Label
Public Sub New()
Me.txtMax1 = New System.Windows.Forms.TextBox
Me.txtMin1 = New System.Windows.Forms.TextBox
Me.txtAvg1 = New System.Windows.Forms.TextBox
Me.txtAvg2 = New System.Windows.Forms.TextBox
Me.txtMin2 = New System.Windows.Forms.TextBox
Me.txtMax2 = New System.Windows.Forms.TextBox
Me.btnStar = New System.Windows.Forms.Button
Me.pb1 = New System.Windows.Forms.ProgressBar
Me.btnStop = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.txtRep = New System.Windows.Forms.TextBox
Me.Label6 = New System.Windows.Forms.Label
Me.lblMINR2 = New System.Windows.Forms.Label
Me.lblMAXR2 = New System.Windows.Forms.Label
Me.lblMINR1 = New System.Windows.Forms.Label
Me.lblMAXR1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'txtMax1
'
Me.txtMax1.BackColor = System.Drawing.Color.White
Me.txtMax1.ForeColor = System.Drawing.Color.Black
Me.txtMax1.Location = New System.Drawing.Point(47, 35)
Me.txtMax1.Name = "txtMax1"
Me.txtMax1.ReadOnly = True
Me.txtMax1.Size = New System.Drawing.Size(100, 20)
Me.txtMax1.TabIndex = 0
'
'txtMin1
'
Me.txtMin1.BackColor = System.Drawing.Color.White
Me.txtMin1.ForeColor = System.Drawing.Color.Black
Me.txtMin1.Location = New System.Drawing.Point(47, 61)
Me.txtMin1.Name = "txtMin1"
Me.txtMin1.ReadOnly = True
Me.txtMin1.Size = New System.Drawing.Size(100, 20)
Me.txtMin1.TabIndex = 1
'
'txtAvg1
'
Me.txtAvg1.BackColor = System.Drawing.Color.White
Me.txtAvg1.ForeColor = System.Drawing.Color.Black
Me.txtAvg1.Location = New System.Drawing.Point(47, 95)
Me.txtAvg1.Name = "txtAvg1"
Me.txtAvg1.ReadOnly = True
Me.txtAvg1.Size = New System.Drawing.Size(100, 20)
Me.txtAvg1.TabIndex = 2
'
'txtAvg2
'
Me.txtAvg2.BackColor = System.Drawing.Color.White
Me.txtAvg2.ForeColor = System.Drawing.Color.Black
Me.txtAvg2.Location = New System.Drawing.Point(204, 95)
Me.txtAvg2.Name = "txtAvg2"
Me.txtAvg2.ReadOnly = True
Me.txtAvg2.Size = New System.Drawing.Size(100, 20)
Me.txtAvg2.TabIndex = 5
'
'txtMin2
'
Me.txtMin2.BackColor = System.Drawing.Color.White
Me.txtMin2.ForeColor = System.Drawing.Color.Black
Me.txtMin2.Location = New System.Drawing.Point(204, 61)
Me.txtMin2.Name = "txtMin2"
Me.txtMin2.ReadOnly = True
Me.txtMin2.Size = New System.Drawing.Size(100, 20)
Me.txtMin2.TabIndex = 4
'
'txtMax2
'
Me.txtMax2.BackColor = System.Drawing.Color.White
Me.txtMax2.ForeColor = System.Drawing.Color.Black
Me.txtMax2.Location = New System.Drawing.Point(204, 35)
Me.txtMax2.Name = "txtMax2"
Me.txtMax2.ReadOnly = True
Me.txtMax2.Size = New System.Drawing.Size(100, 20)
Me.txtMax2.TabIndex = 3
'
'btnStar
'
Me.btnStar.BackColor = System.Drawing.Color.Transparent
Me.btnStar.Location = New System.Drawing.Point(135, 160)
Me.btnStar.Name = "btnStar"
Me.btnStar.Size = New System.Drawing.Size(98, 23)
Me.btnStar.TabIndex = 6
Me.btnStar.Text = "Start"
Me.btnStar.UseVisualStyleBackColor = False
'
'pb1
'
Me.pb1.Location = New System.Drawing.Point(7, 125)
Me.pb1.Name = "pb1"
Me.pb1.Size = New System.Drawing.Size(330, 23)
Me.pb1.TabIndex = 7
'
'btnStop
'
Me.btnStop.BackColor = System.Drawing.Color.Transparent
Me.btnStop.Enabled = False
Me.btnStop.Location = New System.Drawing.Point(239, 160)
Me.btnStop.Name = "btnStop"
Me.btnStop.Size = New System.Drawing.Size(98, 23)
Me.btnStop.TabIndex = 8
Me.btnStop.Text = "Stop"
Me.btnStop.UseVisualStyleBackColor = False
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(248, 7)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(13, 13)
Me.Label1.TabIndex = 9
Me.Label1.Text = "2"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(94, 7)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(13, 13)
Me.Label2.TabIndex = 10
Me.Label2.Text = "1"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(9, 38)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(30, 13)
Me.Label3.TabIndex = 11
Me.Label3.Text = "Max."
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(8, 64)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(27, 13)
Me.Label4.TabIndex = 12
Me.Label4.Text = "Min."
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(8, 98)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(29, 13)
Me.Label5.TabIndex = 13
Me.Label5.Text = "Avg."
'
'txtRep
'
Me.txtRep.Location = New System.Drawing.Point(47, 162)
Me.txtRep.Name = "txtRep"
Me.txtRep.Size = New System.Drawing.Size(69, 20)
Me.txtRep.TabIndex = 14
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(5, 165)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(30, 13)
Me.Label6.TabIndex = 15
Me.Label6.Text = "Rep."
'
'lblMINR2
'
Me.lblMINR2.AutoSize = True
Me.lblMINR2.Font = New System.Drawing.Font("Microsoft Sans Serif", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblMINR2.Location = New System.Drawing.Point(310, 66)
Me.lblMINR2.Name = "lblMINR2"
Me.lblMINR2.Size = New System.Drawing.Size(10, 12)
Me.lblMINR2.TabIndex = 16
Me.lblMINR2.Text = "0"
Me.lblMINR2.Visible = False
'
'lblMAXR2
'
Me.lblMAXR2.AutoSize = True
Me.lblMAXR2.Font = New System.Drawing.Font("Microsoft Sans Serif", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblMAXR2.Location = New System.Drawing.Point(310, 40)
Me.lblMAXR2.Name = "lblMAXR2"
Me.lblMAXR2.Size = New System.Drawing.Size(10, 12)
Me.lblMAXR2.TabIndex = 17
Me.lblMAXR2.Text = "0"
Me.lblMAXR2.Visible = False
'
'lblMINR1
'
Me.lblMINR1.AutoSize = True
Me.lblMINR1.Font = New System.Drawing.Font("Microsoft Sans Serif", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblMINR1.Location = New System.Drawing.Point(153, 66)
Me.lblMINR1.Name = "lblMINR1"
Me.lblMINR1.Size = New System.Drawing.Size(10, 12)
Me.lblMINR1.TabIndex = 18
Me.lblMINR1.Text = "0"
Me.lblMINR1.Visible = False
'
'lblMAXR1
'
Me.lblMAXR1.AutoSize = True
Me.lblMAXR1.Font = New System.Drawing.Font("Microsoft Sans Serif", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblMAXR1.Location = New System.Drawing.Point(153, 40)
Me.lblMAXR1.Name = "lblMAXR1"
Me.lblMAXR1.Size = New System.Drawing.Size(10, 12)
Me.lblMAXR1.TabIndex = 19
Me.lblMAXR1.Text = "0"
Me.lblMAXR1.Visible = False
'
'WT
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(343, 190)
Me.Controls.Add(Me.lblMAXR1)
Me.Controls.Add(Me.lblMINR1)
Me.Controls.Add(Me.lblMAXR2)
Me.Controls.Add(Me.lblMINR2)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.txtRep)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.btnStop)
Me.Controls.Add(Me.pb1)
Me.Controls.Add(Me.btnStar)
Me.Controls.Add(Me.txtAvg2)
Me.Controls.Add(Me.txtMin2)
Me.Controls.Add(Me.txtMax2)
Me.Controls.Add(Me.txtAvg1)
Me.Controls.Add(Me.txtMin1)
Me.Controls.Add(Me.txtMax1)
Me.Name = "WT"
Me.Text = "WT"
Me.TransparencyKey = System.Drawing.Color.Ivory
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Private Sub btnStar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStar.Click
fin = False
btnStop.Enabled = True
btnStar.Enabled = False
proceso()
fin = True
btnStop.Enabled = False
btnStar.Enabled = True
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
fin = True
btnStop.Enabled = False
btnStar.Enabled = True
End Sub
Private Sub max1(ByVal t As Double)
txtMax1.Text = CStr(t)
End Sub
Private Sub max2(ByVal t As Double)
txtMax2.Text = CStr(t)
End Sub
Private Sub min1(ByVal t As Double)
txtMin1.Text = CStr(t)
End Sub
Private Sub min2(ByVal t As Double)
txtMin2.Text = CStr(t)
End Sub
Private Sub avg1(ByVal t As Double)
txtAvg1.Text = CStr(t)
End Sub
Private Sub avg2(ByVal t As Double)
txtAvg2.Text = CStr(t)
End Sub
Private Sub proceso()
Try
Dim ran As Boolean = False
Dim x, y As Long
Dim f As Long
Dim tot As Integer = 1
Dim aux As Double = 0
Dim avgTot As Double = 0
Dim aux2 As Double = 0
Dim avgTot2 As Double = 0
max1(0)
min1(0)
avg1(0)
max2(0)
min2(0)
avg2(0)
If String.IsNullOrEmpty(txtRep.Text) = False Then
If IsNumeric(txtRep.Text) Then
tot = CInt(txtRep.Text)
Else
txtRep.Text = "1"
End If
Else
txtRep.Text = "1"
End If
QueryPerformanceFrequency(f)
pb1.Value = 0
pb1.Maximum = tot
Dim i As Integer = 0
code()
code2()
While i < tot And fin = False
If ran Then
QueryPerformanceCounter(x)
code()
QueryPerformanceCounter(y)
aux = (y - x) * unMillon / f
QueryPerformanceCounter(x)
code2()
QueryPerformanceCounter(y)
aux2 = (y - x) * unMillon / f
ran = Not ran
Else
QueryPerformanceCounter(x)
code2()
QueryPerformanceCounter(y)
aux2 = (y - x) * unMillon / f
QueryPerformanceCounter(x)
code()
QueryPerformanceCounter(y)
aux = (y - x) * unMillon / f
ran = Not ran
End If
avgTot += aux
avgTot2 += aux2
If CDbl(txtMin1.Text) > CStr(aux) Or CDbl(txtMin1.Text) = 0 Then
min1(aux)
lblMINR1.Visible = False
lblMINR1.Text = CStr(1)
ElseIf CDbl(txtMin1.Text) = CStr(aux) Then
lblMINR1.Visible = True
lblMINR1.Text = CStr(CInt(lblMINR1.Text) + 1)
End If
If CDbl(txtMax1.Text) < CStr(aux) Then
max1(aux)
lblMAXR1.Visible = False
lblMAXR1.Text = CStr(1)
ElseIf CDbl(txtMax1.Text) = CStr(aux) Then
lblMAXR1.Visible = True
lblMAXR1.Text = CStr(CInt(lblMAXR1.Text) + 1)
End If
If CDbl(txtMin2.Text) > CStr(aux2) Or CDbl(txtMin2.Text) = 0 Then
min2(aux2)
lblMINR2.Visible = False
lblMINR2.Text = CStr(1)
ElseIf CDbl(txtMin2.Text) = CStr(aux2) Then
lblMINR2.Visible = True
lblMINR2.Text = CStr(CInt(lblMINR2.Text) + 1)
End If
If CDbl(txtMax2.Text) < CStr(aux2) Then
max2(aux2)
lblMAXR2.Visible = False
lblMAXR2.Text = CStr(1)
ElseIf CDbl(txtMax2.Text) = CStr(aux2) Then
lblMAXR2.Visible = True
lblMAXR2.Text = CStr(CInt(lblMAXR2.Text) + 1)
End If
avg1(avgTot / (i + 1))
avg2(avgTot2 / (i + 1))
pb1.Value += 1
Application.DoEvents()
i += 1
End While
pb1.Value = 0
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub code()
'Put here the function 1
End Sub
Private Sub code2()
'Put here the function 2
End Sub
End Class
No comments have been posted about Application to measure the performance of code fragments. Simply put two pieces of code you want to. Why not be the first to post a comment about Application to measure the performance of code fragments. Simply put two pieces of code you want to.