''
DataTables("D").DataRows.Clear
Tables("D").AddNew(10000)
For Each r As Row In Tables("D").Rows
r("C") = rand.NextString(12)
r("T") = rand.NextString(12)
r("U") = rand.NextString(12)
r("A") = rand.Next(500)
r("P") = rand.Next(1500)
Next
Dim st As Date = Date.Now
Dim log As String
Dim f As New Filler
f.SourceTable = DataTables("D") '指定数据来源
f.SourceCols = "C,T,U,A,P" '指定数据来源列
f.DataTable = DataTables("E") '指定数据接收表
f.DataCols = "C,T,U,A,P" '指定数据接收列
f.Fill()
log &= "FILL耗时: " & (Date.Now - st).TotalSeconds & "秒" & vbcrlf
DataTables("E").DataRows.Clear
Dim st2 As Date = Date.Now
Dim x As new List(of DataRow)
For Each dr As DataRow In DataTables("D").DataRows
x.Add(dr)
Next
log &= "得到序列耗时: " & (Date.Now - st2).TotalSeconds & "秒" & vbcrlf
Dim n As Integer = x.Count
log &= "得到行数耗时耗时: " & (Date.Now - st2).TotalSeconds & "秒" & vbcrlf
DataTables("E").AddNew(n)
log &= "增加行耗时: " & (Date.Now - st2).TotalSeconds & "秒" & vbcrlf
For i As Integer = 0 To n - 1
Dim dr As DataRow = DataTables("E").DataRows(i)
dr("C") = x(i)("C")
dr("T") = x(i)("T")
dr("U") = x(i)("U")
dr("A") = x(i)("A")
dr("P") = x(i)("P")
Next
log &= "赋值耗时: " & (Date.Now - st2).TotalSeconds & "秒" & vbcrlf
output.Show(log)
实际测试,如果10000行以内,两种方法相差1秒,但超过万行,达到10万行数据以后,filler需要13秒左右,而后一种方法耗时2倍。
后一种方法还能更快一些吗?