Esempio n. 1
0
        public void IntrospectionSort_SortsNativeArrayWith2MillionEntries()
        {
            const int itemCount = 2000000;

            nativeArray = new NativeArray <int>(itemCount, Allocator.Persistent);
            var rnd = new System.Random(0);

            for (int i = 0; i < nativeArray.Length; ++i)
            {
                nativeArray[i] = rnd.Next(0, itemCount);
            }

            var array = nativeArray.ToArray();

            float x = Time.realtimeSinceStartup;

            Array.Sort(array);
            Debug.Log("Managed: " + (UnityEngine.Time.realtimeSinceStartup - x));


            x = UnityEngine.Time.realtimeSinceStartup;
            NativeArrayAlgorithms.IntrospectiveSort(nativeArray, 0, nativeArray.Length);
            UnityEngine.Debug.Log("Native: " + (UnityEngine.Time.realtimeSinceStartup - x));

            for (int i = 0; i < nativeArray.Length; ++i)
            {
                Assert.AreEqual(array[i], nativeArray[i]);
            }
        }
Esempio n. 2
0
        public void BinarySearch_ReturnsIndexToExistingItemFrom2MLongArray()
        {
            const int searchValueIndex = 65535;
            const int itemCount        = 2000000;

            nativeArray = new NativeArray <int>(itemCount, Allocator.Persistent);
            var rnd = new System.Random(0);

            for (int i = 0; i < nativeArray.Length; ++i)
            {
                nativeArray[i] = rnd.Next(0, itemCount);
            }
            NativeArrayAlgorithms.IntrospectiveSort(nativeArray, 0, nativeArray.Length);

            var managedArr = nativeArray.ToArray();

            float x = Time.realtimeSinceStartup;

            Array.BinarySearch(managedArr, managedArr[searchValueIndex]);
            Debug.Log("Managed Binary Search: " + (Time.realtimeSinceStartup - x));

            x = Time.realtimeSinceStartup;
            NativeArrayAlgorithms.BinarySearch(nativeArray, nativeArray[searchValueIndex]);
            Debug.Log("Native Binary Search: " + (Time.realtimeSinceStartup - x));
        }
Esempio n. 3
0
        public void IntrospectionSort_SortsNativeArray()
        {
            nativeArray = new NativeArray <int>(kDefaultArray, Allocator.Temp);

            NativeArrayAlgorithms.IntrospectiveSort(nativeArray, 0, nativeArray.Length);
            for (int i = 0; i < nativeArray.Length; ++i)
            {
                Assert.AreEqual(kDefaultArraySorted[i], nativeArray[i]);
            }
        }
Esempio n. 4
0
        public IEnumerator IntrospectionSort_withMultipleSeeds_SortsNativeArrayWith500ThousandEntries([Values(-1, 0, 1)] int seed)
        {
            const int itemCount = 500000;

            nativeArray = new NativeArray <int>(itemCount, Allocator.Persistent);
            var rnd = new System.Random(seed);

            for (int i = 0; i < nativeArray.Length; ++i)
            {
                nativeArray[i] = rnd.Next(0, itemCount);
            }
            var array = nativeArray.ToArray();

            Array.Sort(array);
            NativeArrayAlgorithms.IntrospectiveSort(nativeArray, 0, nativeArray.Length);

            for (int i = 0; i < nativeArray.Length; ++i)
            {
                Assert.AreEqual(array[i], nativeArray[i]);
            }
            yield return(null);
        }