コード例 #1
0
ファイル: LxListTest.cs プロジェクト: maxcat/MatchMaking
        public void BenchmarkInsertTail()
        {
            int count     = 128;
            int iteration = 10000;

            int[]        array  = new int[count];
            List <int>   list   = new List <int>(count);
            LxList <int> lxList = new LxList <int>(count);

            Stopwatch watch = new Stopwatch();

            watch.Start();
            watch.Stop();

            // assign test
            for (int i = 0; i < count; ++i)
            {
                array[i] = i;
                list.Add(i);
                lxList.Add(i);
            }

            watch = MatchmakingTest.Measure(() =>
            {
                int[] newArray;
                newArray = new int[array.Length + 1];
                newArray[array.Length] = -1;
                Array.Copy(array, 0, newArray, 1, array.Length);
                array = newArray;
            }, iteration);
            Debug.Log($"array insert tail copy {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                Array.Resize(ref array, array.Length + 1);
                array[array.Length - 1] = -1;
            }, iteration);
            Debug.Log($"array insert tail resize {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                list.Add(-1);
            }, iteration);
            Debug.Log($"list insert tail {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                lxList.Add(-1);
            }, iteration);
            Debug.Log($"lxList insert tail {watch.ElapsedMilliseconds}");
        }
コード例 #2
0
ファイル: LxListTest.cs プロジェクト: maxcat/MatchMaking
        public void BenchmarkInsertMiddle()
        {
            int count = 100;

            int[]        array  = new int[count];
            List <int>   list   = new List <int>(count);
            LxList <int> lxList = new LxList <int>(count);

            Stopwatch watch = new Stopwatch();

            watch.Start();
            watch.Stop();

            // assign test
            for (int i = 0; i < count; ++i)
            {
                array[i] = i;
                list.Add(i);
                lxList.Add(i);
            }

            int iteration = 10000;

            int[] newArray;
            // insert middle
            int middleIndex = count / 2;

            watch = MatchmakingTest.Measure(() =>
            {
                lxList.Insert(middleIndex, -1);
            }, iteration);
            Debug.Log($"lxlist insert middle ticks {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                newArray = new int[array.Length + 1];
                newArray[middleIndex] = -1;
                Array.Copy(array, 0, newArray, 0, middleIndex);
                Array.Copy(array, middleIndex, newArray, middleIndex + 1, array.Length - middleIndex);
                array = newArray;
            }, iteration);
            Debug.Log($"array insert middle {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                list.Insert(middleIndex, -1);
            }, iteration);
            Debug.Log($"list insert middle ticks {watch.ElapsedMilliseconds}");
        }
コード例 #3
0
ファイル: LxListTest.cs プロジェクト: maxcat/MatchMaking
        public void BenchmarkInsertHead()
        {
            int count     = 128;
            int iteration = 10000;

            int[]        array  = new int[count];
            List <int>   list   = new List <int>(count);
            LxList <int> lxList = new LxList <int>(count);

            Stopwatch watch;

            // assign test
            for (int i = 0; i < count; ++i)
            {
                array[i] = i;
                list.Add(i);
                lxList.Add(i);
            }

            watch = MatchmakingTest.Measure(() =>
            {
                int[] newArray;
                // insert head test
                newArray    = new int[array.Length + 1];
                newArray[0] = -1;
                Array.Copy(array, 0, newArray, 1, array.Length);
                array = newArray;
            }, iteration);
            Debug.Log($"array insert head {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                list.Insert(0, -1);
            }, iteration);
            Debug.Log($"list insert head {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                lxList.Insert(0, -1);
            }, iteration);
            Debug.Log($"lxList insert head {watch.ElapsedMilliseconds}");
        }
コード例 #4
0
ファイル: LxListTest.cs プロジェクト: maxcat/MatchMaking
        public void BenchmarkAssign()
        {
            int count     = 128;
            int iteration = 10000;

            int[]        array  = new int[count];
            List <int>   list   = new List <int>(count);
            LxList <int> lxList = new LxList <int>(count);

            Stopwatch watch;

            // assign test
            watch = MatchmakingTest.Measure(() =>
            {
                for (int i = 0; i < count; ++i)
                {
                    array[i] = i;
                }
            }, iteration);
            Debug.Log($"array assign ticks {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                for (int i = 0; i < count; ++i)
                {
                    list.Add(i);
                }
                list.Clear();
            }, iteration);
            Debug.Log($"list assign ticks {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                for (int i = 0; i < count; ++i)
                {
                    lxList.Add(i);
                }
                lxList.Reset();
            }, iteration);
            Debug.Log($"lx list assign ticks {watch.ElapsedMilliseconds}");
        }
コード例 #5
0
ファイル: LxListTest.cs プロジェクト: maxcat/MatchMaking
        public void BenchmarkGet()
        {
            int count     = 128;
            int iteration = 1000000;

            int[]        array  = new int[count];
            List <int>   list   = new List <int>(count);
            LxList <int> lxList = new LxList <int>(count);

            Stopwatch watch;
            int       result;
            int       index = 10;

            // assign test
            for (int i = 0; i < count; ++i)
            {
                array[i] = i;
                list.Add(i);
                lxList.Add(i);
            }

            // access test
            watch = MatchmakingTest.Measure(() =>
            {
                result = array[index];
            }, iteration);
            Debug.Log($"array access ticks {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                result = list[index];
            }, iteration);
            Debug.Log($"list access ticks {watch.ElapsedMilliseconds}");

            watch = MatchmakingTest.Measure(() =>
            {
                result = lxList.Get(index);
            }, iteration);
            Debug.Log($"lx list access ticks {watch.ElapsedMilliseconds}");
        }