Foxtable(狐表)用户栏目专家坐堂 → [求助]这段代码快在哪里?


  共有2471人关注过本帖树形打印复制链接

主题:[求助]这段代码快在哪里?

帅哥哟,离线,有人找我吗?
天一生水
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1141 积分:11272 威望:0 精华:0 注册:2017/9/26 16:30:00
[求助]这段代码快在哪里?  发帖心情 Post By:2020/9/20 20:09:00 [显示全部帖子]

老师好!

下面两段代码,都是遍历后(共2500个股piao名称)新增行,只不过第二段代码是在遍历过程中又以遍历100个为一组再循环遍历。并没有涉及多线程的运用,速度却提高几十倍。

1、是快在哪里了?

2、是不是遍历都可以采用这种方式?

请老师指教!

谢谢!

 

第一段代码:

 

Dim obj_down As New System.Net.WebClient()
Dim drs As List(Of DataRow) = DataTables("表D").Select("股piao代码 is not null")
For Each dr As DataRow In drs
    Dim data As String = obj_down.DownloadString("http://hq.sinajs.cn/list=" & dr("股piao代码"))
    Dim start As Integer = data.IndexOf("""") + 1
    Dim en As Integer = data.IndexOf(""";")
    Dim datas() As String = data.SubString(start, en - start).Split(",")
    dr("股piao名字") = datas(0)
    dr("今日开盘") = datas(1)
    dr("昨日收盘") = datas(2)
Next

 

第二段代码:

DataTables("表D").ResumeRedraw

Dim wc As New System.Net.WebClient()
DataTables("表D").StopRedraw

Dim len As Integer = 100
Dim i As Integer = 1
Dim count As Integer = 1
Dim str As String = ""

Dim drs As List(Of DataRow) = DataTables("表D").Select("股piao代码 Is not null")
For Each dr As DataRow In drs
    str &= dr("股piao代码") & ","
   
    If i >= len * count OrElse i = drs.Count Then
        Output.Show("count:" & count)
        Output.Show(len & "-" & count & "-" & len * count)
        Output.Show("i:" & i)

        Dim data As String = wc.DownloadString("http://hq.sinajs.cn/list=" & str.Trim(",")).Trim()
        Dim idx As Integer = iif(i = drs.Count, drs.Count - len*(count-1), len)
        Output.Show("idx:" & idx)
        For Each d As String In data.Split(";")
            If idx >= 0 AndAlso d <> "" Then
               
                Dim r As DataRow = drs(i - idx)
                Output.Show("(i - idx):" & (i - idx))
                Dim start As Integer = d.IndexOf("""") + 1
                Dim en As Integer = d.LastIndexOf("""")
                Dim datas() As String = d.SubString(start, en - start).Split(",")
                If datas.length >= 4 Then                    
                    r("股piao名字") = datas(0)
                    r("今日开盘") = datas(1)
                    r("昨日收盘") = datas(2)   
                End If
            End If           
            idx -= 1
        Next
        count += 1
        str = ""
    End If
    i += 1
Next

DataTables("表D").ResumeRedraw

 

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:股价示例.table

[此贴子已经被作者于2020/9/20 20:25:21编辑过]

 回到顶部