第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的代碼需要這么長時間才能返回結(jié)果?

為什么我的代碼需要這么長時間才能返回結(jié)果?

Go
翻閱古今 2023-07-10 10:58:03
運(yùn)行此代碼時,我必須等待 10 秒才能打印 s.Locations,并等待 60 秒以上才能打印 n.Titles。是什么原因造成的?有關(guān)如何解決此問題的提示會很有幫助,即查看完成某些代碼行需要多長時間。Go 新手,所以不確定如何具體執(zhí)行此操作。我已確保關(guān)閉我的聯(lián)系。由于我計算機(jī)上的其他所有內(nèi)容加載速度都非??欤虼宋艺J(rèn)為通過 http.Get 訪問互聯(lián)網(wǎng)不會很慢。package mainimport (    "encoding/xml"    "fmt"    "io/ioutil"    "net/http"    "strings")// SitemapIndex is the root xmltype SitemapIndex struct {    Locations []string `xml:"sitemap>loc"`}// News is the individual categoriestype News struct {    Titles    []string `xml:"url>news>title"`    Keywords  []string `xml:"url>news>keywords"`    Locations []string `xml:"url>loc"`}// NewsMap is thetype NewsMap struct {    Keywords string    Location string}func main() {    var s SitemapIndex    var n News    // np := make(map[string]NewsMap)    resp, _ := http.Get("https://www.washingtonpost.com/news-sitemaps/index.xml")    bytes, _ := ioutil.ReadAll(resp.Body)    xml.Unmarshal(bytes, &s)    resp.Body.Close()    for i := range s.Locations {        s.Locations[i] = strings.TrimSpace(s.Locations[i])    }    fmt.Println(s.Locations) // slice of data    for _, Location := range s.Locations {        resp, _ := http.Get(Location)        bytes, _ := ioutil.ReadAll(resp.Body)        xml.Unmarshal(bytes, &n)        resp.Body.Close()    }    fmt.Println(n.Titles)}我得到了輸出,但 s.Locations 需要等待 10 秒,n.Titles 需要等待 60 秒以上
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號