1

私のアプリケーションの動きの鈍さは、以下のタイミングで計測されているコードのビットまでたどることができました。これが遅いポイントになることはわかっていましたが、各リクエストには平均で 1 秒かかります。私が求めている xml のビットは常に最初のタグにあるので、ダウンロード時間ではないと思います。

Stopwatch stopwatch = new Stopwatch();
XmlTextReader reader = new XmlTextReader("http://steamcommunity.com/id/test?xml=1");

stopwatch.Reset();
stopwatch.Start();

while (reader.Read()) {
 if (reader.Name.Equals("steamID64")) {
  reader.Read();

  stopwatch.Stop();

  time = stopwatch.ElapsedMilliseconds();
  return Convert.ToInt64(reader.Value);
 }
}

必要なタグを読み取るためのより高速な方法はありますか、または xml ファイルをダウンロードしているサーバーによって制限されていますか?

ありがとう。

4

4 に答える 4

3

接続を作成するのにかかる時間を測定していると思います。それを確認するために、Reset+Start 行をリーダーの作成の上に移動できます。ほとんどまたはまったく違いはないと思います。

それが接続時間である場合、それはネットワーク次第であり、コードで実行できることに注意してください。ネットワーク設定を微調整することで改善できる場合があります。しかし、それは別のフォーラムのためのものです。

于 2010-08-26T21:50:58.090 に答える
1

だから私はダウンロード時間ではないと思います

これを確認するために、ファイルをローカルにダウンロードして、時刻を確認することを検討しましたか?

于 2010-08-26T21:55:31.420 に答える
1

設定してみてください

reader.XmlResolver = null;
于 2010-08-26T21:52:39.510 に答える
1

あなたの方法を別の方法と比較しました。データをダウンロードして、正規表現で ID を見つけるだけです。

        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Reset();
        stopwatch.Start();

        System.Net.WebClient wc = new System.Net.WebClient();
        string s = wc.DownloadString("http://steamcommunity.com/id/test?xml=1");
        System.Text.RegularExpressions.Regex re = new Regex("\\<steamID64\\>(\\d+)\\</steamID64\\>");
        System.Text.RegularExpressions.Match m = re.Match(s);
        if (m != null && m.Captures.Count != 0) Response.Write("steamID64: " + m.Captures[0].Value + " <br/>");
        stopwatch.Stop();

        long time = stopwatch.ElapsedMilliseconds;
        Response.Write("Time Elapsed (1):" + time.ToString() +" <br/>");

        stopwatch.Reset();
        stopwatch.Start();

        System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader("http://steamcommunity.com/id/test?xml=1");

        stopwatch.Reset();
        stopwatch.Start();

        while (reader.Read())
        {
            if (reader.Name.Equals("steamID64"))
            {
                reader.Read();
                stopwatch.Stop();

                time = stopwatch.ElapsedMilliseconds;
                s = reader.Value;
                break;
            }
        }

        Response.Write("<br/>steamID64: " + s );
        Response.Write("<br/>Time Elapsed (2):" + time.ToString() + " <br/>");

** 結果:

steamID64: 76561197991558078 経過時間 (1):1572

steamID64: 76561197991558078 経過時間 (2):969

XmlReaderの方が優れています:)。

于 2010-08-26T22:12:39.713 に答える