public static void Execute()
    {
        SSUtil.Log("executing {0}", typeof(T06_matrix_caching).Name);

        Matrix4x4 ret = Matrix4x4.zero;

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_caching: no caching_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                ret = Camera.main.worldToCameraMatrix * _inputMat;
            }
        }

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_caching: cached_"))
        {
            Matrix4x4 cached = Camera.main.worldToCameraMatrix;
            for (int i = 0; i < NUM; i++)
            {
                ret = cached * _inputMat;
            }
        }
    }
Ejemplo n.º 2
0
    public static string Execute()
    {
        SSUtil.Log("executing {0}", typeof(T03_enum_string).Name);

        using (SSTimer t = new SSTimer("_test_enum_to_string"))
        {
            for (int i = 0; i < NUM; i++)
            {
                for (int k = 0; k < (int)FooTypes.Max; k++)
                {
                    foo = ((FooTypes)k).ToString();
                }
            }
        }
        foo = "";

        using (SSTimer t = new SSTimer("_test_enum_get_name"))
        {
            for (int i = 0; i < NUM; i++)
            {
                for (int k = 0; k < (int)FooTypes.Max; k++)
                {
                    foo = Enum.GetName(typeof(FooTypes), (FooTypes)k);
                }
            }
        }
        foo = "";

        return(foo); // prevent 'foo' from being optimized out
    }
Ejemplo n.º 3
0
    void Start()
    {
        SSUtil.Log("high-res: {0}, freq: {1}, timestamp: {2}",
                   Stopwatch.IsHighResolution, Stopwatch.Frequency, Stopwatch.GetTimestamp());

        T01_foreach.Execute();
        T03_enum_string.Execute();
        T04_typecast.Execute();
        T05_matrix.Execute();
        T06_matrix_caching.Execute();
    }
Ejemplo n.º 4
0
    public static void Execute()
    {
        SSUtil.Log("executing {0}", typeof(T01_foreach).Name);

        for (int i = 0; i < NUM; i++)
        {
            _testArray[i] = i;
        }

        for (int i = 0; i < NUM; i++)
        {
            _testList.Add(i);
        }

        for (int i = 0; i < NUM; i++)
        {
            _testDict[i] = i;
        }

        int sum = 0;

        using (SSTimer t = new SSTimer("_testArray"))
        {
            foreach (var item in _testArray)
            {
                sum += item;
            }
        }

        using (SSTimer t = new SSTimer("_testList"))
        {
            foreach (var item in _testList)
            {
                sum += item;
            }
        }

        using (SSTimer t = new SSTimer("_testDict"))
        {
            foreach (var item in _testList)
            {
                sum += item;
            }
        }
    }
Ejemplo n.º 5
0
    public static void Execute()
    {
        SSUtil.Log("executing {0}", typeof(T04_typecast).Name);

        Foo f = new Bar();

        using (SSTimer t = new SSTimer("_test_as_cast_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                Bar b = f as Bar;
                b.dummy_derived = 1;
            }
        }

        using (SSTimer t = new SSTimer("_test_c_style_cast_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                Bar b = (Bar)f;
                b.dummy_derived = 1;
            }
        }
    }
Ejemplo n.º 6
0
    public static void Execute()
    {
        SSUtil.Log("executing {0}", typeof(T05_matrix).Name);

        // testing correctness

        ResetRandomly();
        Matrix4x4 r0 = _m1 * _m2;
        Matrix4x4 r1 = SSMatrix.Mul_v1_naive(_m1, _m2);
        Matrix4x4 r2 = SSMatrix.Mul_v2_naive_expanded(_m1, _m2);
        Matrix4x4 r3 = Matrix4x4.zero;

        SSMatrix.Mul_v3_ref(ref r3, ref _m1, ref _m2);
        SSUtil.Assert(r0 == r1, "matrix r1 bad result.");
        SSUtil.Assert(r0 == r2, "matrix r2 bad result.");
        SSUtil.Assert(r0 == r3, "matrix r3 bad result.");

        // 'Mul_v4_for_3d_trans' always produce the same 4th row
        Matrix4x4 r4 = Matrix4x4.zero;

        SSMatrix.Mul_v4_for_3d_trans(ref r4, ref _m1, ref _m2);
        Matrix4x4 r4_target = r0;

        r4_target.SetRow(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
        SSUtil.Assert(r4 == r4_target, "matrix r4 bad result.");

        // testing performances

        Matrix4x4 ret = Matrix4x4.zero;

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_mul: Unity Built-In_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                ret = _m1 * _m2;
            }
        }

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_mul: v1 - Naive Implementation_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                ret = SSMatrix.Mul_v1_naive(_m1, _m2);
            }
        }

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_mul: v2 - Naive (Expanded)_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                ret = SSMatrix.Mul_v2_naive_expanded(_m1, _m2);
            }
        }

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_mul: v3 - ref passed & returned_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                SSMatrix.Mul_v3_ref(ref ret, ref _m1, ref _m2);
            }
        }

        ResetRandomly();
        using (SSTimer t = new SSTimer("_test_mat_mul: v4 - for 3d transform only_"))
        {
            for (int i = 0; i < NUM; i++)
            {
                SSMatrix.Mul_v4_for_3d_trans(ref ret, ref _m1, ref _m2);
            }
        }
    }
Ejemplo n.º 7
0
 public void Dispose()
 {
     _stopWatch.Stop();
     SSUtil.Log("'{0}' exec time: {1:0.000} (ms)", _tag, ((double)_stopWatch.ElapsedTicks / (double)Stopwatch.Frequency) * 1000);
 }