【问题标题】:String iteration c# mono字符串迭代 c# mono
【发布时间】:2023-04-10 18:03:03
【问题描述】:

我有长度为 2418060 个字符的字符串。 该字符串包含数字、大括号和一些特殊符号。这是一个样本

!(242.9288)F(562.7884)/(45)!(242.9288)F(126.8685)&(18.95)F(126.8685)!(140.2591)F(114.399)&

它是 LindermayerSystem,所以每个字符都有空间动作,括号中的数字是变量。

我怎样才能快速迭代这个?当我通过简单的 for 循环逐个字符迭代时,它持续了 10 分钟,而 Unity 在此之后没有响应.. 当然里面我有开关:

switch (array[i])
             {
                 //TurnLeft
                 case '+':
                     i+=2;
                     do
                     {
                         checkingString.Append(array[i]);
                         i++;
                     } while (array[i] != ')');

                     value=float.Parse(checkingString.ToString());

                     currentPosRot.rotation = Quaternion.AngleAxis(value, Vector3.left) * currentPosRot.rotation;

                    //position = position + (rotation * new Vector3(0, 2, 0));

                    //curve.AddPointAt(position);


                    checkingString = new StringBuilder();

                     value = 0.0f;
                     break;
                 //Turn right
                 case '-': ...

【问题讨论】:

  • 为什么投反对票?

标签: c# string unity3d mono


【解决方案1】:

这是一个优化问题。我假设在这种特定情况下,第二个优化规则将适用:不要优化。

第 1 步:将您的输入数据(2 MB 字符串)缩减为可测试的合理大小。使您能够附加 Unity 分析器并在 10 秒内获得性能结果。

第 2 步:配置文件。查看处理时间的确切去向。

第 3 步:选择前 1 次消费者并对其进行改进,以减少其处理能力。然后从第 2 步重新开始,直到您的性能问题得到解决。

【讨论】:

    猜你喜欢
    • 2011-07-22
    • 2017-12-15
    • 2018-05-02
    • 2015-07-04
    • 1970-01-01
    • 2014-04-21
    • 2016-08-08
    • 2017-01-29
    • 1970-01-01
    相关资源
    最近更新 更多