Exemple #1
0
        public void RayIntersectAABBPerformance()
        {
#if DEBUG
            // my laptop in High Performance mode
            const double minMillionRaysPerSec = 0.32;
            const double maxMillionRaysPerSec = 0.55;
#elif APPVEYOR_PERFORMANCE_MARGINS
            // AppVeyor build server
            const double minMillionRaysPerSec = 2.9;
            const double maxMillionRaysPerSec = 4.1;
#else
            // my laptop in High Performance mode
            const double minMillionRaysPerSec = 1.2;
            const double maxMillionRaysPerSec = 2.5;
#endif

            const int numRays    = 1000000;
            var       box        = new AxisAlignedBox(new Vector(-0.5, -0.5, -0.5), new Vector(0.5, 0.5, 0.5));
            var       numRaysHit = 0;

            DateTime startTime = DateTime.Now;
            for (var i = 0; i < numRays; i++)
            {
                //var start = new Vector(0.5, 0.5, 0.5);
                var start = MakeRandomVector(-0.3, 0.3, -0.3, 0.3, 0.5, 1);
                var dir   = MakeRandomVector(-0.5, 0.5, -0.5, 0.5, -1, -1);
                //var dir = MakeRandomVector(1, 1, -1);
                var info = box.IntersectRay(start, dir, context);
                if (info != null)
                {
                    numRaysHit++;
                }
            }
            var elapsedTime = DateTime.Now - startTime;
            Assert.IsTrue(numRays * 0.998 < numRaysHit && numRaysHit <= numRays * 1.0, "Num rays hit {0} should be roughly the same as total rays {1}", numRaysHit, numRays);
            var millionRaysPerSec = numRays / 1000000.0 / elapsedTime.TotalSeconds;
            Assert.IsTrue(minMillionRaysPerSec < millionRaysPerSec && millionRaysPerSec < maxMillionRaysPerSec,
                          "Rays per second {0:f3} not between {1} and {2} (millions)", millionRaysPerSec, minMillionRaysPerSec, maxMillionRaysPerSec);
            Console.WriteLine("Performance: {0} million rays per second", millionRaysPerSec);
        }