public static void Test(int tests) { var random = new Random(0); var testxs = new uint[tests]; var testys = new uint[tests]; for (int i = 0; i < tests; i++) { testxs[i] = (uint)random.Next(Int32.MaxValue); testys[i] = (uint)random.Next(Int32.MaxValue); } var results1 = new long[tests]; var results2 = new ulong[tests]; for (int i = 0; i < results1.Length; i++) { results1[i] = i; } for (uint i = 0; i < results2.Length; i++) { results2[i] = i; } var stopwatch = System.Diagnostics.Stopwatch.StartNew(); stopwatch.Restart(); for (int i = 0; i < tests; i++) { results1[i] = HilbertCurve.xy2d(32, (int)testxs[i], (int)testys[i]); } Console.WriteLine("Slow encode:\t{0:0.00}ns/record", stopwatch.ElapsedMilliseconds / (tests / 1000000.0)); stopwatch.Restart(); for (int i = 0; i < tests; i++) { int x = 0, y = 0; HilbertCurve.d2xy(32, results1[i], out x, out y); } Console.WriteLine("Slow decode:\t{0:0.00}ns/record", stopwatch.ElapsedMilliseconds / (tests / 1000000.0)); stopwatch.Restart(); for (int i = 0; i < tests; i++) { results2[i] = HilbertCurve.xy2dByte(testxs[i], testys[i]); } Console.WriteLine("Fast encode:\t{0:0.00}ns/record", stopwatch.ElapsedMilliseconds / (tests / 1000000.0)); stopwatch.Restart(); for (int i = 0; i < tests; i++) { uint x = 0, y = 0; HilbertCurve.d2xyByte((ulong)results2[i], out x, out y); } Console.WriteLine("Fast decode:\t{0:0.00}ns/record", stopwatch.ElapsedMilliseconds / (tests / 1000000.0)); for (int i = 0; i < tests; i++) { if (results1[i] != (long)results2[i]) { Console.WriteLine("Error! ({0}, {1}) -> [ {2}, {3} ]", testxs[i], testys[i], results1[i], results2[i]); } uint x = 0; uint y = 0; HilbertCurve.d2xyByte((ulong)results1[i], out x, out y); if (x != testxs[i] || y != testys[i]) { Console.WriteLine("Error!!! {4} -> ({0}, {2}) != ({1}, {3})", x, testxs[i], y, testys[i], results1[i]); Console.ReadLine(); } } }