public IEnumerator Test()
        {
            var amount = PerformanceComparisonConfig.ObjectCount;

            Random.InitState(0);
            var s = Stopwatch.StartNew();

            for (int i = 0; i < amount; i++)
            {
                var collider = new GameObject().AddComponent <UnityEngine.BoxCollider>();
                collider.transform.position = PerformanceComparisonConfig.GetRandomPosition();
                collider.size = PerformanceComparisonConfig.GetRandomSize();
            }

            Debug.Log("Creating go's took (but can't measure broad phase construction): " + s.Elapsed.TotalMilliseconds);

            yield return(null);

            var raycastAmount = PerformanceComparisonConfig.RaycastAmount;

            RaycastHit[] results = new RaycastHit[amount];
            int          hits    = 0;

            s.Restart();
            for (int i = 0; i < raycastAmount; i++)
            {
                var d = PerformanceComparisonConfig.RayEnd - PerformanceComparisonConfig.RayStart;
                hits = Physics.RaycastNonAlloc(PerformanceComparisonConfig.RayStart, math.normalize(d), results, math.length(d));
            }

            Debug.Log("Raycasts took: " + s.Elapsed.TotalMilliseconds + " results: " + hits);
        }
        private void DoTest()
        {
            var amount = PerformanceComparisonConfig.ObjectCount;
            var world  = new BVHTreeWorld(amount, Allocator.Persistent);

            Random.InitState(0);
            var colliders  = new NativeArray <Collider>(amount, Allocator.TempJob);
            var transforms = new NativeArray <RigidTransform>(amount, Allocator.TempJob);

            for (int i = 0; i < PerformanceComparisonConfig.ObjectCount; i++)
            {
                colliders[i]  = BoxCollider.Create(float3.zero, PerformanceComparisonConfig.GetRandomSize());
                transforms[i] = new RigidTransform(quaternion.identity, PerformanceComparisonConfig.GetRandomPosition());
            }


            var s = Stopwatch.StartNew();

            Profiler.BeginSample("broad");
            new BVHTreeWorld.InsertCollidersAndTransformsJob {
                Tree       = world.tree,
                Bodies     = world.bodies,
                Colliders  = colliders,
                Transforms = transforms
            }.Run();
            Profiler.EndSample();
            if (enableLog)
            {
                Debug.Log("Building broad phase took: " + s.Elapsed.TotalMilliseconds);
            }

            var rayResult = new NativeList <int>(64, Allocator.TempJob);

            var start = PerformanceComparisonConfig.RayStart;
            var end   = PerformanceComparisonConfig.RayEnd;

            var rayJob = new RayJob {
                Tree     = world.tree,
                RayInput = new NativeBVHTree.Ray {
                    origin      = start,
                    direction   = math.normalize(end - start),
                    maxDistance = math.distance(start, end),
                },
                Results = rayResult
            };

            s.Restart();
            rayJob.Run();
            if (enableLog)
            {
                Debug.Log("Raycasts took: " + s.Elapsed.TotalMilliseconds + " results: " + rayResult.Length);
            }

            s.Restart();
            world.Update();
            if (enableLog)
            {
                Debug.Log("Building broad phase again after no changes took: " + s.Elapsed.TotalMilliseconds);
            }

            for (int i = 0; i < 100; i++)
            {
                int randomIndex = Random.Range(1, PerformanceComparisonConfig.ObjectCount);
                world.UpdateTransform(randomIndex, new RigidTransform(quaternion.identity, PerformanceComparisonConfig.GetRandomPosition()));
            }
            s.Restart();
            world.Update();
            if (enableLog)
            {
                Debug.Log("Building broad phase again after some changes took: " + s.Elapsed.TotalMilliseconds);
            }
        }