以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  新版为何感觉从后台读取数据慢多了  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=174368)

--  作者:hbhb
--  发布时间:2022/1/12 13:11:00
--  新版为何感觉从后台读取数据慢多了
大师:新版为何感觉从后台读取数据慢多了(sql语句)?
--  作者:有点蓝
--  发布时间:2022/1/12 13:48:00
--  
可能新版样式等新增加功能造成的吧
--  作者:hbhb
--  发布时间:2022/1/12 14:58:00
--  
Dim st As Date = Date.Now

Dim lst1 As New List(of DataRow)
Dim lst2 As New List(of DataRow)
For Each dr As DataRow In DataTables("表A").DataRows
    If DataTables("表A").Find("第二列 = " & dr("第一列")) Is Nothing Then
        lst1.Add(dr)
    Else
        lst2.Add(dr)
    End If
Next
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒") \'计算并显示执行代码所花费的秒数


帮助中说执行以上代码0.8秒,目前新版执行8秒。什么情况?慢了10倍??????


--  作者:hbhb
--  发布时间:2022/1/12 15:01:00
--  
如果是select求行集合,那就更慢了?
--  作者:有点蓝
--  发布时间:2022/1/12 15:08:00
--  
请提供实例测试
--  作者:狐狸爸爸
--  发布时间:2022/1/12 15:10:00
--  
我测试了一下,第一列和第二列,都是整数型,分别用foxtable 2019和2022测试,用时都是0.10秒:


Tables("表A").addNew(10000)
For Each r As Row In Tables("表A").Rows
    r("第一列") = rand.Next(1,20000)
    r("第二列") = rand.Next(1,20000)
Next

Dim st As Date = Date.Now
Dim lst1 As New List(of DataRow)
Dim lst2 As New List(of DataRow)
For Each dr As DataRow In DataTables("表A").DataRows
    If DataTables("表A").Find("第二列 = " & dr("第一列")) Is Nothing Then
        lst1.Add(dr)
    Else
        lst2.Add(dr)
    End If
Next
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒") \'计算并显示执行代码所花费的秒数

--  作者:hbhb
--  发布时间:2022/1/12 16:01:00
--  
您是整数,如果是字符串呢?

Tables("表B").addNew(10000)
For Each r As Row In Tables("表B").Rows
    r("第一列") = "2"
    r("第二列") = "2"
Next

Dim st As Date = Date.Now
Dim lst1 As New List(of DataRow)
Dim lst2 As New List(of DataRow)
For Each dr As DataRow In DataTables("表B").DataRows
    If DataTables("表B").Find("第二列 = \'" & dr("第一列") & "\'") Is Nothing Then
        lst1.Add(dr)
    Else
        lst2.Add(dr)
    End If
Next

Output.Show(lst1.Count)
Output.Show(lst2.Count)
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒") \'计算并显示执行代码所花费的秒数



--  作者:狐狸爸爸
--  发布时间:2022/1/12 16:04:00
--  
字符型的话,2022版2.9秒,2019版3.5秒,新版本更快。
--  作者:hbhb
--  发布时间:2022/1/12 16:38:00
--  
如果字符串较长,应该时间还要长?
--  作者:狐狸爸爸
--  发布时间:2022/1/12 16:44:00
--  
按道理是这样的,不过下面的代码,在新版同样不到0.2秒完成,速度还可以:

Tables("表A").addNew(10000)
For Each r As Row In Tables("表A").Rows
    r("第一列") = rand.NextString(16)
    r("第二列") = rand.NextString(16)
Next

Dim st As Date = Date.Now
Dim lst1 As New List(of DataRow)
Dim lst2 As New List(of DataRow)
For Each dr As DataRow In DataTables("表A").DataRows
    If DataTables("表A").Find("第二列 = \'" & dr("第一列") & "\'") Is Nothing Then
        lst1.Add(dr)
    Else
        lst2.Add(dr)
    End If
Next
MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒") \'计算并显示执行代码所花费的秒数