public void TestPositiveDoubling()
        {
            var inputA = new AlgorithmDebuggingInitialValueDelegate
            {
                GetValueForPosition = (x, y, z, i, j, k) =>
                {
                    return((int)(1));
                }
            };

            int computations;
            var increment = new AlgorithmIncrementWaterDistance();

            var runtimeInput = new RuntimeLayer(inputA);
            var runtimeTest  = new RuntimeLayer(increment);

            runtimeTest.SetInput(0, runtimeInput);

            var result = runtimeTest.GenerateData(0, 0, 0, 16, 16, 16, out computations);


            for (var i = 0; i < 16; i++)
            {
                for (var j = 0; j < 16; j++)
                {
                    for (var k = 0; k < 16; k++)
                    {
                        Assert.True(
                            result[i + j * 16 + k * 16 * 16] == 2);
                    }
                }
            }
        }
示例#2
0
        public void TestCompileGradient()
        {
            int computations1, computations2;
            int width = 16, height = 16, depth = 16;
            var gradient    = new RuntimeLayer(new AlgorithmGradientInitial());
            var passthrough = new RuntimeLayer(new AlgorithmPassthrough());

            passthrough.SetInput(0, gradient);
            var i1 = gradient.GenerateData(0, 0, 0, width, height, depth, out computations1);

            var c1 = LayerCompiler.Compile(gradient).GenerateData(0, 0, 0, width, height, depth, out computations1);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        Assert.Equal(
                            i1[x + y * width + z * width * height],
                            c1[x + y * width + z * width * height],
                            "Value differs in gradient compare.");
                    }
                }
            }
        }
示例#3
0
        private void TestRuntimePassthrough(int xBorder, int yBorder)
        {
            int computations1, computations2;
            int width = 16, height = 16, depth = 16;
            var gradient    = new RuntimeLayer(new AlgorithmGradientInitial());
            var passthrough = new RuntimeLayer(new AlgorithmPassthrough {
                XBorder = xBorder, YBorder = yBorder
            });

            passthrough.SetInput(0, gradient);
            var i1 = gradient.GenerateData(0, 0, 0, width, height, depth, out computations1);
            var i2 = passthrough.GenerateData(0, 0, 0, width, height, depth, out computations2);

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    for (var z = 0; z < depth; z++)
                    {
                        Assert.Equal(i1[x + y * width + z * width * height], i2[x + y * width + z * width * height]);
                    }
                }
            }
            //, "Value differs in passthrough (" + xBorder + ", " + yBorder + ").");
        }
示例#4
0
        public void ZoomSquareTest()
        {
            int computations1, computations2;
            int width = 16, height = 16, depth = 16;
            var gradient = new RuntimeLayer(new AlgorithmGradientInitial());
            var zoom     = new RuntimeLayer(new AlgorithmZoom2D {
                Mode = AlgorithmZoom2D.ZoomType.Square
            });

            zoom.SetInput(0, gradient);
            var i1 = gradient.GenerateData(0, 0, 0, width, height, depth, out computations1);
            var i2 = zoom.GenerateData(0, 0, 0, width, height, depth, out computations2);

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    for (var k = 0; k < depth; k++)
                    {
                        Assert.Equal(
                            i1[i / 2 + j / 2 * width + k / 2 * width * height],
                            i2[i + j * width + k * width * height]);
                    }
                }
            }
            //,
            //               "Square zoom is not working for (" + i + ", " + j + ", " + k + ").");
        }
示例#5
0
        public void TestForOCXOddAdjustmentShutterBug()
        {
            int computations;
            var input = new AlgorithmDebuggingInitialDelegate
            {
                ValueShouldBePlacedAt = (x, y, z) => true
            };
            var zoom = new AlgorithmZoom2D
            {
                Mode = AlgorithmZoom2D.ZoomType.Square
            };
            var runtimeInput = new RuntimeLayer(input);
            var runtimeZoom  = new RuntimeLayer(zoom);

            runtimeZoom.SetInput(0, runtimeInput);
            var result = runtimeZoom.GenerateData(1, 0, 0, 32, 32, 32, out computations);

            // We have filled the entire block, therefore this bug can be detected by checking
            // every odd row.
            for (var x = 1; x < 32; x += 2)
            {
                Assert.True(result[x + 0 * 32 + 0 * 32 * 32] == 1);
            }
            //, "OCX odd adjustment shutter bug is present, where every odd row is blank when main adjustment is an odd number.");
        }
示例#6
0
        public static void TestAlgorithmIncrementWaterDistance4()
        {
            var algorithmInitial                 = new AlgorithmInitialBool();
            var algorithmZoom2DIteration1        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration2        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration3        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration4        = new AlgorithmZoom2D();
            var algorithmIncrementWaterDistance1 = new AlgorithmIncrementWaterDistance()
            {
                Initial = true
            };
            var algorithmIncrementWaterDistance2 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance3 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance4 = new AlgorithmIncrementWaterDistance();
            var runtimeInitial                 = new RuntimeLayer(algorithmInitial);
            var runtimeZoom2DIteration1        = new RuntimeLayer(algorithmZoom2DIteration1);
            var runtimeZoom2DIteration2        = new RuntimeLayer(algorithmZoom2DIteration2);
            var runtimeZoom2DIteration3        = new RuntimeLayer(algorithmZoom2DIteration3);
            var runtimeZoom2DIteration4        = new RuntimeLayer(algorithmZoom2DIteration4);
            var runtimeIncrementWaterDistance1 = new RuntimeLayer(algorithmIncrementWaterDistance1);
            var runtimeIncrementWaterDistance2 = new RuntimeLayer(algorithmIncrementWaterDistance2);
            var runtimeIncrementWaterDistance3 = new RuntimeLayer(algorithmIncrementWaterDistance3);
            var runtimeIncrementWaterDistance4 = new RuntimeLayer(algorithmIncrementWaterDistance4);

            runtimeZoom2DIteration1.SetInput(0, runtimeInitial);
            runtimeIncrementWaterDistance1.SetInput(0, runtimeZoom2DIteration1);
            runtimeZoom2DIteration2.SetInput(0, runtimeIncrementWaterDistance1);
            runtimeIncrementWaterDistance2.SetInput(0, runtimeZoom2DIteration2);
            runtimeZoom2DIteration3.SetInput(0, runtimeIncrementWaterDistance2);
            runtimeIncrementWaterDistance3.SetInput(0, runtimeZoom2DIteration3);
            runtimeZoom2DIteration4.SetInput(0, runtimeIncrementWaterDistance3);
            runtimeIncrementWaterDistance4.SetInput(0, runtimeZoom2DIteration4);
            PerformSampling("AlgorithmIncrementWaterDistance (4 iterations)", runtimeIncrementWaterDistance4);
        }
示例#7
0
        public static void Main(string[] args)
        {
            // Create algorithm setup.
            var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom3       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmZoom4       = new RuntimeLayer(new AlgorithmZoom2D());
            var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());

            algorithmZoom4.SetInput(0, algorithmInitialLand);
            algorithmZoom3.SetInput(0, algorithmZoom4);
            algorithmZoom2.SetInput(0, algorithmZoom3);
            algorithmZoom1.SetInput(0, algorithmZoom2);

            StorageLayer[] storage = null;
            Console.WriteLine("Storing...");
            using (var writer = new StreamWriter("WorldConfig.xml", false))
                StorageAccess.SaveStorage(
                    new StorageLayer[] { StorageAccess.FromRuntime(algorithmZoom1) }, writer);

            Console.WriteLine("Loading...");
            using (var reader = new StreamReader("WorldConfig.xml"))
                storage = StorageAccess.LoadStorage(reader);
            foreach (var l in storage)
            {
                Console.WriteLine(l.Algorithm.GetType().FullName);
            }
        }
示例#8
0
        public static void TestAlgorithmZoom2DIteration1()
        {
            var algorithmInitial          = new AlgorithmInitialBool();
            var algorithmZoom2DIteration1 = new AlgorithmZoom2D();
            var runtimeInitial            = new RuntimeLayer(algorithmInitial);
            var runtimeZoom2DIteration1   = new RuntimeLayer(algorithmZoom2DIteration1);

            runtimeZoom2DIteration1.SetInput(0, runtimeInitial);
            PerformSampling("AlgorithmZoom2D (1 iteration)", runtimeZoom2DIteration1);
        }
示例#9
0
        public static void TestAlgorithmIncrementWaterDistance1()
        {
            var algorithmInitial = new AlgorithmInitialBool();
            var algorithmIncrementWaterDistance = new AlgorithmIncrementWaterDistance()
            {
                Initial = true
            };
            var runtimeInitial = new RuntimeLayer(algorithmInitial);
            var runtimeIncrementWaterDistance = new RuntimeLayer(algorithmIncrementWaterDistance);

            runtimeIncrementWaterDistance.SetInput(0, runtimeInitial);
            PerformSampling("AlgorithmIncrementWaterDistance", runtimeIncrementWaterDistance);
        }
示例#10
0
        public void TestValueRetrievalAcrossBorder()
        {
            int computations;
            var inputA = new AlgorithmDebuggingInitialDelegate
            {
                ValueShouldBePlacedAt = (x, y, z) => (x >= 4 && x <= 6 && y >= 4 && y <= 6)
            };
            var test = new AlgorithmDebuggingDelegate
            {
                Delegate = (context, input, output, x, y, z, i, j, k, width, height, depth, ox, oy, oz) =>
                {
                    int v00 = input[((i - 1) + ox) + ((j - 1) + oy) * width + (k + oz) * width * height];
                    int v01 = input[((i - 1) + ox) + ((j + 0) + oy) * width + (k + oz) * width * height];
                    int v02 = input[((i - 1) + ox) + ((j + 1) + oy) * width + (k + oz) * width * height];
                    int v10 = input[((i + 0) + ox) + ((j - 1) + oy) * width + (k + oz) * width * height];
                    int v11 = input[((i + 0) + ox) + ((j + 0) + oy) * width + (k + oz) * width * height];
                    int v12 = input[((i + 0) + ox) + ((j + 1) + oy) * width + (k + oz) * width * height];
                    int v20 = input[((i + 1) + ox) + ((j - 1) + oy) * width + (k + oz) * width * height];
                    int v21 = input[((i + 1) + ox) + ((j + 0) + oy) * width + (k + oz) * width * height];
                    int v22 = input[((i + 1) + ox) + ((j + 1) + oy) * width + (k + oz) * width * height];

                    Assert.True(v00 == ((5 <= x && x <= 7 && 5 <= y && y <= 7) ? 1 : 0), "v00 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v01 == ((5 <= x && x <= 7 && 4 <= y && y <= 6) ? 1 : 0), "v01 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v02 == ((5 <= x && x <= 7 && 3 <= y && y <= 5) ? 1 : 0), "v02 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v10 == ((4 <= x && x <= 6 && 5 <= y && y <= 7) ? 1 : 0), "v10 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v11 == ((4 <= x && x <= 6 && 4 <= y && y <= 6) ? 1 : 0), "v11 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v12 == ((4 <= x && x <= 6 && 3 <= y && y <= 5) ? 1 : 0), "v12 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v20 == ((3 <= x && x <= 5 && 5 <= y && y <= 7) ? 1 : 0), "v20 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v21 == ((3 <= x && x <= 5 && 4 <= y && y <= 6) ? 1 : 0), "v21 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                    Assert.True(v22 == ((3 <= x && x <= 5 && 3 <= y && y <= 5) ? 1 : 0), "v22 != 1 when x == " + x + " && y == " + y + " && i == " + i + " && j == " + j);
                }
            };
            var runtimeInput = new RuntimeLayer(inputA);
            var runtimeTest  = new RuntimeLayer(test);

            runtimeTest.SetInput(0, runtimeInput);

            // Test this stuff.
            for (int i = -10; i < 10; i++)
            {
                runtimeTest.GenerateData(i, i, i, 10, 10, 10, out computations);
            }
        }
示例#11
0
        public void TestYSkew()
        {
            int computations;
            var input = new AlgorithmDebuggingInitialDelegate
            {
                ValueShouldBePlacedAt = (x, y, z) => (x == 0 && z == 0)
            };
            var passthrough       = new AlgorithmPassthrough();
            var runtimeInput      = new RuntimeLayer(input);
            var runtimePassthough = new RuntimeLayer(passthrough);

            runtimePassthough.SetInput(0, runtimeInput);

            // We need to check with various borders.
            for (var i = 0; i < 2; i++)
            {
                for (var j = 0; j < 2; j++)
                {
                    for (var k = 0; k < 2; k++)
                    {
                        passthrough.XBorder = i;
                        passthrough.YBorder = j;
                        passthrough.ZBorder = k;
                        var result = runtimePassthough.GenerateData(-16, 0, -16, 32, 32, 32, out computations);

                        // Test the area where we should be filled.
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.True(result[16 + y * 32 + 16 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value missing.");
                        }

                        // Test the areas where we should not be filled.
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[17 + y * 32 + 15 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (1, " + y + ", -1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[16 + y * 32 + 15 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (0, " + y + ", -1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[15 + y * 32 + 15 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (-1, " + y + ", -1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[17 + y * 32 + 16 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (1, " + y + ", 0).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[15 + y * 32 + 16 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (-1, " + y + ", 0).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[17 + y * 32 + 17 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (1, " + y + ", 1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[16 + y * 32 + 17 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (0, " + y + ", 1).");
                        }
                        for (var y = 0; y < 32; y += 1)
                        {
                            Assert.False(result[15 + y * 32 + 17 * 32 * 32] == 1, "Skew present on the Y axis with borders (" + i + ", " + j + ", " + k + "), value present at (-1, " + y + ", 1).");
                        }
                    }
                }
            }
        }
示例#12
0
文件: Main.cs 项目: duaneking/Tychaia
        public static void Main(string[] args)
        {
            Layer        legacy                   = null;
            RuntimeLayer algorithmRuntime         = null;
            IGenerator   algorithmCompiled        = null;
            IGenerator   algorithmCompiledBuiltin = null;
            string       mode = "quadzoom";

            if (args.Length > 0)
            {
                mode = args[0];
            }

            // Create initial layers from both types.
            if (mode == "quadzoom")
            {
                legacy = new LayerZoom(new LayerZoom(new LayerZoom(new LayerZoom(new LayerInitialLand()))));
                var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom3       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom4       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());
                algorithmZoom4.SetInput(0, algorithmInitialLand);
                algorithmZoom3.SetInput(0, algorithmZoom4);
                algorithmZoom2.SetInput(0, algorithmZoom3);
                algorithmZoom1.SetInput(0, algorithmZoom2);
                algorithmRuntime = algorithmZoom1;
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
                //algorithmCompiledBuiltin = new CompiledLayerBuiltin();
            }
            else if (mode == "doublezoom")
            {
                legacy = new LayerZoom(new LayerZoom(new LayerInitialLand()));
                var algorithmZoom1       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmZoom2       = new RuntimeLayer(new AlgorithmZoom2D());
                var algorithmInitialLand = new RuntimeLayer(new AlgorithmInitialBool());
                algorithmZoom2.SetInput(0, algorithmInitialLand);
                algorithmZoom1.SetInput(0, algorithmZoom2);
                algorithmRuntime = algorithmZoom1;
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "zoom")
            {
                legacy           = new LayerZoom(new LayerInitialLand());
                algorithmRuntime = new RuntimeLayer(new AlgorithmZoom2D());
                algorithmRuntime.SetInput(0, new RuntimeLayer(new AlgorithmInitialBool()));
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "test")
            {
                var algorithmTest1    = new RuntimeLayer(new AlgorithmPassthrough());
                var algorithmTest2    = new RuntimeLayer(new AlgorithmPassthrough());
                var algorithmConstant = new RuntimeLayer(new AlgorithmConstant {
                    Constant = 5
                });
                algorithmTest2.SetInput(0, algorithmConstant);
                algorithmTest1.SetInput(0, algorithmTest2);
                algorithmRuntime = algorithmTest1;
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "extend")
            {
                legacy           = null;
                algorithmRuntime = new RuntimeLayer(new AlgorithmExtend2D());
                algorithmRuntime.SetInput(0, new RuntimeLayer(new AlgorithmInitialBool()));
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else if (mode == "land")
            {
                legacy           = new LayerInitialLand();
                algorithmRuntime = new RuntimeLayer(new AlgorithmInitialBool());
#if !RANGED_LOGIC_TEST
                algorithmCompiled = LayerCompiler.Compile(algorithmRuntime);
#endif
            }
            else
            {
                Console.WriteLine("usage: ProceduralGenPerformance.exe [doublezoom|zoom|land]");
                return;
            }

#if MODULO_SPEED_TEST
            for (int i = 0; i <= 10000000; i += 1)
            {
                if ((i & 71) < 0 || (i & 71) >= 10000000)
                {
                    Console.WriteLine("AND DOES NOT WORK FOR " + i + ".");
                }
            }
            int a            = 0;
            var andStartTime = DateTime.Now;
            for (int i = 0; i < 10000000; i += 1)
            {
                a = i & 71;
            }
            var andEndTime   = DateTime.Now;
            var modStartTime = DateTime.Now;
            for (int i = 0; i < 10000000; i += 1)
            {
                a = i % 71;
            }
            var modEndTime = DateTime.Now;
            Console.WriteLine("BITAND OPERATION TOOK: " + (andEndTime - andStartTime).TotalMilliseconds + "ms");
            Console.WriteLine("MODULO OPERATION TOOK: " + (modEndTime - modStartTime).TotalMilliseconds + "ms");
#endif

#if VERIFICATION
            #region Verification

            // Verify integrity between algorithms.
            try
            {
                int   vcomputations;
                int[] legacyData   = legacy.GenerateData(0, 0, 16, 16);
                int[] runtimeData  = algorithmRuntime.GenerateData(0, 0, 0, 16, 16, 1, out vcomputations);
                int[] compiledData = algorithmCompiled.GenerateData(0, 0, 0, 16, 16, 1, out vcomputations);
                if (runtimeData.Length != legacyData.Length)
                {
                    Console.WriteLine("STOP: Runtime data evaluation results in a " +
                                      "different array size than the legacy system.");
                    return;
                }
                if (compiledData.Length != legacyData.Length)
                {
                    Console.WriteLine("STOP: Compiled data evaluation results in a " +
                                      "different array size than the legacy system.");
                    return;
                }
                for (var i = 0; i < legacyData.Length; i++)
                {
                    if (runtimeData[i] != legacyData[i])
                    {
                        Console.WriteLine("WARNING: Runtime algorithm results in different data to legacy system.");
                        break;
                    }
                }
                for (var i = 0; i < legacyData.Length; i++)
                {
                    if (compiledData[i] != legacyData[i])
                    {
                        Console.WriteLine("WARNING: Compiled algorithm results in different data to legacy system.");
                        break;
                    }
                }
                for (var i = 0; i < legacyData.Length; i++)
                {
                    if (runtimeData[i] != compiledData[i])
                    {
                        Console.WriteLine("STOP: Runtime algorithm results in different data to compiled algorithm.");
                        for (var x = 0; x < 16; x++)
                        {
                            for (var y = 0; y < 16; y++)
                            {
                                if (runtimeData[x + y * 16] != compiledData[x + y * 16])
                                {
                                    Console.Write(compiledData[x + y * 16]);
                                }
                                else
                                {
                                    Console.Write(" ");
                                }
                            }
                            Console.WriteLine();
                        }
                        break;
                    }
                }
                Console.WriteLine("=== SAMPLE FROM RUNTIME =====");
                for (var x = 0; x < 16; x++)
                {
                    for (var y = 0; y < 16; y++)
                    {
                        Console.Write(runtimeData[x + y * 16]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("=== SAMPLE FROM COMPILED ====");
                for (var x = 0; x < 16; x++)
                {
                    for (var y = 0; y < 16; y++)
                    {
                        Console.Write(compiledData[x + y * 16]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("=============================");
            }
            catch
            {
                // The generation of data failed... could be a dodgy
                // algorithm implementation breaking.
                Console.WriteLine("Verification not possible (check algorithm implementations).");
            }

            #endregion
#endif

#if RANGED_LOGIC_TEST
            var ranged = new RangedLayer(algorithmRuntime);
            Console.WriteLine(ranged.GetPrintableStructure());

            ICSharpCode.NRefactory.CSharp.Expression ix, iy, iz, iwidth, iheight, idepth;
            RangedLayer.FindMaximumBounds(ranged, out ix, out iy, out iz, out iwidth, out iheight, out idepth);
            Console.WriteLine("The X expression is: " + ix.ToString());
            Console.WriteLine("The Y expression is: " + iy.ToString());
            Console.WriteLine("The Z expression is: " + iz.ToString());
            Console.WriteLine("The W expression is: " + iwidth.ToString());
            Console.WriteLine("The H expression is: " + iheight.ToString());
            Console.WriteLine("The D expression is: " + idepth.ToString());
            return;
#endif

            // Run tests to see how fast they are.
            for (int x = 0; x < 300; x++)
            {
                int computations    = 0;
                var legacyFailed    = false;
                var legacyStartTime = DateTime.Now;
                try
                {
                    if (legacy != null)
                    {
                        Console.WriteLine("Starting Test #" + x + " (legacy)");
                        for (int i = 0; i < 1000; i++)
                        {
                            legacy.GenerateData(0, 0, 128, 128);
                        }
                    }
                }
                catch
                {
                    legacyFailed = true;
                }
                var legacyEndTime = DateTime.Now;
                Console.WriteLine("Starting Test #" + x + " (algorithm runtime)");
                var algorithmRuntimeFailed    = false;
                var algorithmRuntimeStartTime = DateTime.Now;
                try
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        algorithmRuntime.GenerateData(0, 0, 0, 128, 128, 1, out computations);
                    }
                }
                catch
                {
                    algorithmRuntimeFailed = true;
                }
                var algorithmRuntimeEndTime = DateTime.Now;
                Console.WriteLine("Starting Test #" + x + " (algorithm compiled)");
                var algorithmCompiledFailed    = false;
                var algorithmCompiledStartTime = DateTime.Now;
                try
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        algorithmCompiled.GenerateData(0, 0, 0, 128, 128, 1, out computations);
                    }
                }
                catch
                {
                    algorithmCompiledFailed = true;
                }
                var algorithmCompiledEndTime          = DateTime.Now;
                var algorithmCompiledBuiltinStartTime = DateTime.Now;
                var algorithmCompiledBuiltinEndTime   = DateTime.Now;
                if (algorithmCompiledBuiltin != null)
                {
                    Console.WriteLine("Starting Test #" + x + " (algorithm compiled builtin)");
                    algorithmCompiledBuiltinStartTime = DateTime.Now;
                    for (int i = 0; i < 1000; i++)
                    {
                        algorithmCompiled.GenerateData(0, 0, 0, 128, 128, 1, out computations);
                    }
                    algorithmCompiledBuiltinEndTime = DateTime.Now;
                }

                // Because there are 1000 tests, and 1000 microseconds in a millisecond..
                Console.Write("Test #" + x);
                PrintStatus(
                    "LEGACY",
                    legacyFailed,
                    legacyStartTime,
                    legacyEndTime);
                PrintStatus(
                    "ALGORITHM RUNTIME",
                    algorithmRuntimeFailed,
                    algorithmRuntimeStartTime,
                    algorithmRuntimeEndTime);
                PrintStatus(
                    "ALGORITHM COMPILED",
                    algorithmCompiledFailed,
                    algorithmCompiledStartTime,
                    algorithmCompiledEndTime);
                PrintStatus(
                    "ALGORITHM COMPILED BUILTIN",
                    algorithmCompiledBuiltin != null,
                    algorithmCompiledBuiltinStartTime,
                    algorithmCompiledBuiltinEndTime);
                Console.WriteLine(
                    "LC%: " + ((legacyEndTime - legacyStartTime).TotalMilliseconds /
                               (algorithmCompiledEndTime - algorithmCompiledStartTime).TotalMilliseconds)
                    * 100 + "% "
                    );
            }
        }
示例#13
0
文件: Main.cs 项目: duaneking/Tychaia
        public static void Main(string[] args)
        {
            var algorithmInitial                 = new AlgorithmInitialBool();
            var algorithmZoom2DIteration1        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration2        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration3        = new AlgorithmZoom2D();
            var algorithmZoom2DIteration4        = new AlgorithmZoom2D();
            var algorithmIncrementWaterDistance1 = new AlgorithmIncrementWaterDistance()
            {
                Initial = true
            };
            var algorithmIncrementWaterDistance2 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance3 = new AlgorithmIncrementWaterDistance();
            var algorithmIncrementWaterDistance4 = new AlgorithmIncrementWaterDistance();
            var runtimeInitial                 = new RuntimeLayer(algorithmInitial);
            var runtimeZoom2DIteration1        = new RuntimeLayer(algorithmZoom2DIteration1);
            var runtimeZoom2DIteration2        = new RuntimeLayer(algorithmZoom2DIteration2);
            var runtimeZoom2DIteration3        = new RuntimeLayer(algorithmZoom2DIteration3);
            var runtimeZoom2DIteration4        = new RuntimeLayer(algorithmZoom2DIteration4);
            var runtimeIncrementWaterDistance1 = new RuntimeLayer(algorithmIncrementWaterDistance1);
            var runtimeIncrementWaterDistance2 = new RuntimeLayer(algorithmIncrementWaterDistance2);
            var runtimeIncrementWaterDistance3 = new RuntimeLayer(algorithmIncrementWaterDistance3);
            var runtimeIncrementWaterDistance4 = new RuntimeLayer(algorithmIncrementWaterDistance4);

            runtimeZoom2DIteration1.SetInput(0, runtimeInitial);
            runtimeIncrementWaterDistance1.SetInput(0, runtimeZoom2DIteration1);
            runtimeZoom2DIteration2.SetInput(0, runtimeIncrementWaterDistance1);
            runtimeIncrementWaterDistance2.SetInput(0, runtimeZoom2DIteration2);
            runtimeZoom2DIteration3.SetInput(0, runtimeIncrementWaterDistance2);
            runtimeIncrementWaterDistance3.SetInput(0, runtimeZoom2DIteration3);
            runtimeZoom2DIteration4.SetInput(0, runtimeIncrementWaterDistance3);
            runtimeIncrementWaterDistance4.SetInput(0, runtimeZoom2DIteration4);

            runtimeInitial.Userdata                 = "runtimeInitial";
            runtimeZoom2DIteration1.Userdata        = "runtimeZoom2DIteration1";
            runtimeIncrementWaterDistance1.Userdata = "runtimeIncrementWaterDistance1";
            runtimeZoom2DIteration2.Userdata        = "runtimeZoom2DIteration2";
            runtimeIncrementWaterDistance2.Userdata = "runtimeIncrementWaterDistance2";
            runtimeZoom2DIteration3.Userdata        = "runtimeZoom2DIteration3";
            runtimeIncrementWaterDistance3.Userdata = "runtimeIncrementWaterDistance3";
            runtimeZoom2DIteration4.Userdata        = "runtimeZoom2DIteration4";
            runtimeIncrementWaterDistance4.Userdata = "runtimeIncrementWaterDistance4";

            EnableHandler = () =>
            {
                runtimeInitial.DataGenerated                 += HandleDataGenerated;
                runtimeZoom2DIteration1.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance1.DataGenerated += HandleDataGenerated;
                runtimeZoom2DIteration2.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance2.DataGenerated += HandleDataGenerated;
                runtimeZoom2DIteration3.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance3.DataGenerated += HandleDataGenerated;
                runtimeZoom2DIteration4.DataGenerated        += HandleDataGenerated;
                runtimeIncrementWaterDistance4.DataGenerated += HandleDataGenerated;
            };

            DisableHandler = () =>
            {
                runtimeInitial.DataGenerated                 -= HandleDataGenerated;
                runtimeZoom2DIteration1.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance1.DataGenerated -= HandleDataGenerated;
                runtimeZoom2DIteration2.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance2.DataGenerated -= HandleDataGenerated;
                runtimeZoom2DIteration3.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance3.DataGenerated -= HandleDataGenerated;
                runtimeZoom2DIteration4.DataGenerated        -= HandleDataGenerated;
                runtimeIncrementWaterDistance4.DataGenerated -= HandleDataGenerated;
            };

            EnableHandler();

            var s = 64;
            var o = 10000000;
            int computations;

            runtimeIncrementWaterDistance4.GenerateData(-s + o, -s + o, -s + o, s * 2, s * 2, s * 2, out computations);
        }