コード例 #1
0
        public static void TestMathPerf()
        {
            IntVec3       intVec        = new IntVec3(72, 0, 65);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Math perf tests (" + 1E+07f + " tests each)");
            float     num       = 0f;
            Stopwatch stopwatch = Stopwatch.StartNew();
            int       num2      = 0;

            while ((float)num2 < 1E+07f)
            {
                num += (float)Math.Sqrt(101.20999908447266);
                num2++;
            }
            stringBuilder.AppendLine(string.Concat(new object[]
            {
                "(float)System.Math.Sqrt(",
                101.21f,
                "): ",
                stopwatch.ElapsedTicks
            }));
            Stopwatch stopwatch2 = Stopwatch.StartNew();
            int       num3       = 0;

            while ((float)num3 < 1E+07f)
            {
                num += Mathf.Sqrt(101.21f);
                num3++;
            }
            stringBuilder.AppendLine(string.Concat(new object[]
            {
                "UnityEngine.Mathf.Sqrt(",
                101.21f,
                "): ",
                stopwatch2.ElapsedTicks
            }));
            Stopwatch stopwatch3 = Stopwatch.StartNew();
            int       num4       = 0;

            while ((float)num4 < 1E+07f)
            {
                num += GenMath.Sqrt(101.21f);
                num4++;
            }
            stringBuilder.AppendLine(string.Concat(new object[]
            {
                "Verse.GenMath.Sqrt(",
                101.21f,
                "): ",
                stopwatch3.ElapsedTicks
            }));
            Stopwatch stopwatch4 = Stopwatch.StartNew();
            int       num5       = 0;

            while ((float)num5 < 1E+07f)
            {
                num += (float)intVec.LengthManhattan;
                num5++;
            }
            stringBuilder.AppendLine("Verse.IntVec3.LengthManhattan: " + stopwatch4.ElapsedTicks);
            Stopwatch stopwatch5 = Stopwatch.StartNew();
            int       num6       = 0;

            while ((float)num6 < 1E+07f)
            {
                num += intVec.LengthHorizontal;
                num6++;
            }
            stringBuilder.AppendLine("Verse.IntVec3.LengthHorizontal: " + stopwatch5.ElapsedTicks);
            Stopwatch stopwatch6 = Stopwatch.StartNew();
            int       num7       = 0;

            while ((float)num7 < 1E+07f)
            {
                num += (float)intVec.LengthHorizontalSquared;
                num7++;
            }
            stringBuilder.AppendLine("Verse.IntVec3.LengthHorizontalSquared: " + stopwatch6.ElapsedTicks);
            stringBuilder.AppendLine("total: " + num);
            Log.Message(stringBuilder.ToString(), false);
        }