Public Class FormSpeedTest
Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
btnRun.Enabled = False
Call WriteArrayListData()
Call WriteCustomerObjectData()
Call WriteDataTableData()
btnRun.Enabled = True
End Sub
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
btnRead.Enabled = False
Call ReadArrayListData()
Call ReadCustomerObjectData()
Call ReadFromCustomerTable()
Call ReadFromCustomerTableOptimization1()
Call ReadFromCustomerTableOptimization2()
'Call ReadXMLFromCustomerTable()
btnRead.Enabled = True
End Sub
'/***********************ARRAY LIST Functionality ****************************************/
Private Function WriteToArrayListByValue(ByVal custID As Int32, ByVal custName As String, ByVal custSex As Boolean, _
ByVal custSalary As Decimal, ByVal custMaritalStatus As Char, ByVal custDOB As DateTime) As Object
Dim arrCustomer As New ArrayList()
arrCustomer.Add(custID)
arrCustomer.Add(custName)
arrCustomer.Add(custSex)
arrCustomer.Add(custSalary)
arrCustomer.Add(custMaritalStatus)
arrCustomer.Add(custDOB)
Return arrCustomer
End Function
Private Function WriteToArrayListFromArrayList(ByVal arrCust As ArrayList) As Object
Dim arrCustomer As New ArrayList()
arrCustomer.Add(arrCust(0))
arrCustomer.Add(arrCust(1))
arrCustomer.Add(arrCust(2))
arrCustomer.Add(arrCust(3))
arrCustomer.Add(arrCust(4))
arrCustomer.Add(arrCust(5))
Return arrCustomer
End Function
Private Sub WriteArrayListData()
Dim stpWatch1 As New Diagnostics.Stopwatch
Dim customerList As New ArrayList
Dim customerObj As New List(Of SpeedTestCustomer)
Dim s As Boolean = False
Dim l As Decimal = CDec(1.278)
Dim m As Char = CChar("S")
Dim d As DateTime = #1/1/1901#
stpWatch1.Start()
For i As Integer = 0 To 1000000
customerList.Add(WriteToArrayListByValue(i, "Customer Name " & i.ToString, s, l * i, m, d))
If s Then s = False Else s = True
If m = "S" Then m = CChar("M") Else m = CChar("S")
d = DateAdd(DateInterval.Day, 1, d)
Next
stpWatch1.Stop()
lblArrayListWriteMsg.Text = "Loading an ArrayList Object with " & customerList.Count.ToString & " Items. Total Duration : " & (stpWatch1.ElapsedMilliseconds / 1000).ToString & " Seconds."
End Sub
Private Sub ReadArrayListData()
Dim stpWatch1 As New Diagnostics.Stopwatch
Dim customerList As New ArrayList
Dim custX As New ArrayList
Dim s As Boolean = False
Dim l As Decimal = CDec(1.278)
Dim m As Char = CChar("S")
Dim d As DateTime = #1/1/1901#
'/*************LOAD FIRST ********************************/
For i As Integer = 0 To 1000000
customerList.Add(WriteToArrayListByValue(i, "Customer Name " & i.ToString, s, 1 * i, m, d))
If s Then s = False Else s = True
If m = "S" Then m = CChar("M") Else m = CChar("S")
d = DateAdd(DateInterval.Day, 1, d)
Next
stpWatch1.Start()
For i As Integer = 0 To customerList.Count - 1
custX.Add(WriteToArrayListFromArrayList(CType(customerList(i), ArrayList)))
Next
stpWatch1.Start()
lblArrayListReadMsg.Text = "Reading an ArrayList Object with " & customerList.Count.ToString & " Items. Total Duration : " & (stpWatch1.ElapsedMilliseconds / 1000).ToString & " Seconds."
End Sub
'/***********************Data Table Functionality ****************************************/
Private Function CreateCustomerTable() As DataTable
Dim dt As New DataTable("Customer")
Dim dc1 As New DataColumn("CustId", GetType(Integer))
Dim dc2 As New DataColumn("Name", GetType(String))
Dim dc3 As New DataColumn("Sex", GetType(Boolean))
Dim dc4 As New DataColumn("Salary", GetType(Decimal))
Dim dc5 As New DataColumn("MaritalStatus", GetType(Char))
Dim dc6 As New DataColumn("BirthDate", GetType(DateTime))
dt.Columns.Add(dc1)
dt.Columns.Add(dc2)
dt.Columns.Add(dc3)
dt.Columns.Add(dc4)
dt.Columns.Add(dc5)
dt.Columns.Add(dc6)
Return dt
End Function
Private Sub WriteDataTableData()
Dim stpWatch3 As New Diagnostics.Stopwatch
Dim custTable As New DataTable
custTable = CreateCustomerTable()
Dim s As Boolean = False
Dim l As Decimal = CDec(1.278)
Dim m As Char = CChar("S")
Dim d As DateTime = #1/1/1901#
stpWatch3.Start()
For i As Integer = 0 To 1000000
Dim dr As DataRow = custTable.NewRow
dr("CustID") = i
dr("Name") = "Customer Name " & i.ToString
dr("Sex") = s
dr("Salary") = l * i
dr("MaritalStatus") = m
dr("BirthDate") = d
custTable.Rows.Add(dr)
If s Then s = False Else s = True
If m = "S" Then m = CChar("M") Else m = CChar("S")
d = DateAdd(DateInterval.Day, 1, d)
Next
stpWatch3.Stop()
lblTableWriteMsg.Text = "Loading a Data Table Object with " & custTable.Rows.Count.ToString & " Items. Total Duration :" & (stpWatch3.ElapsedMilliseconds / 1000).ToString & " Seconds."
End Sub
Private Sub ReadFromCustomerTable()
Dim stpWatch4 As New Diagnostics.Stopwatch
Dim custTable As New DataTable
custTable = CreateCustomerTable()
Dim s As Boolean = False
Dim l As Decimal = CDec(1.278)
Dim m As Char = CChar("S")
Dim d As DateTime = #1/1/1901#
For i As Integer = 0 To 1000000
Dim dr As DataRow = custTable.NewRow
dr("CustID") = i
dr("Name") = "Customer Name " & i.ToString
dr("Sex") = s
dr("Salary") = l * i
dr("MaritalStatus") = m
dr("BirthDate") = d
custTable.Rows.Add(dr)
If s Then s = False Else s = True
If m = CChar("S") Then m = CChar("M") Else m = CChar("S")
d = DateAdd(DateInterval.Day, 1, d)
Next