gpt4 book ai didi

c# - 加速解析算法

转载 作者:太空狗 更新时间:2023-10-30 00:08:52 27 4
gpt4 key购买 nike

我正在尝试解析一些 ddump 文件,你能帮我加快我的算法吗?
每个循环需要 216 毫秒!!那太过分了。我希望每个循环大约有 40-50 毫秒。也许通过使用 RegExp?

这是我的算法:

 while (pos < EntireFile.Length && (/*curr = */EntireFile.Substring(pos, EntireFile.Length - pos)).Contains(" class"))            {                w.Reset();                w.Start();                pos = EntireFile.ToLower().IndexOf(" class", pos) + 6;                int end11 = EntireFile.ToLower().IndexOf("extends", pos);                if (end11 == -1)                    end11 = EntireFile.IndexOf("\r\n", pos);                else                {                    int end22 = EntireFile.IndexOf("\r\n", pos);                    if (end22 < end11)                        end11 = end22;                }                //string opcods = EntireFile.Substring(pos, EntireFile.Length - pos);                string Cname = EntireFile.Substring(pos, end11 - pos).Trim();                pos += (end11 - pos) + 7;                pos = EntireFile.IndexOf("{", pos) +1;

int count = 1;
string searching = EntireFile.Substring(pos, EntireFile.Length - pos);
int searched = 0;
while (count != 0)
{
if (searching[searched] == '{')
count++;
else if (searching[searched] == '}')
count--;

searched++;
}
string Content = EntireFile.Substring(pos, searched);
tlist.Add(new TClass() { ClassName = Cname, Content = Content });
pos += searched;

if (pos % 3 == 0)
{
double prc = ((double)pos) * 100d / ((double)EntireFile.Length);
int prcc = (int)Math.Round(prc);
wnd.UpdateStatus(prcc);
wnd.Update();
}
mils.Add((int)w.ElapsedMilliseconds);
}

如有任何帮助,我们将不胜感激。

最佳答案

好吧,多次这样做

EntireFile.ToLower()

肯定没用。您可以做几件事:

  1. 只执行一次代价高昂的操作(ToLowerIndexOf 等)并尽可能缓存结果。
  2. 不要缩小您正在使用 SubString 处理的输入,这会降低您的性能。相反,保留一个单独的 int parseStart 值并将其用作所有 IndexOf 调用的附加参数。换句话说,跟踪您手动解析的文件部分,而不是每次都取一个较小的子字符串。

关于c# - 加速解析算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5261687/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com