Example #1
0
        public void GetHashCodeShouldBeComputedLazyAndShouldBeVeryFast()
        {
            var geometryCount = 1000000;
            var geometries = new IGeometry[geometryCount];

            for (int i = 0; i < geometryCount; i++)
            {
                geometries[i] = new Polygon(new LinearRing(new[] { new Coordinate(1.0, 2.0), new Coordinate(2.0, 3.0), new Coordinate(3.0, 4.0), new Coordinate(1.0, 2.0) }));
            }

            var polygon = new Polygon(new LinearRing(new[] { new Coordinate(1.0, 2.0), new Coordinate(2.0, 3.0), new Coordinate(3.0, 4.0), new Coordinate(1.0, 2.0) }));

            // computes hash code every call
            var t0 = DateTime.Now;
            for (int i = 0; i < geometryCount; i++)
            {
                geometries[i].GetHashCode();
            }
            var t1 = DateTime.Now;

            var dt1 = t1 - t0;

            // computes hash code only first time (lazy)
            t0 = DateTime.Now;
            for (int i = 0; i < geometryCount; i++)
            {
                polygon.GetHashCode();
            }
            t1 = DateTime.Now;

            var dt2 = t1 - t0;

            Assert.IsTrue(dt2.TotalMilliseconds < 15 * dt1.TotalMilliseconds);
        }
Example #2
0
        public void CompareUsingHashcode()
        {
            var polygon = new Polygon(new LinearRing(new[] { new Coordinate(1.0, 2.0), new Coordinate(2.0, 3.0), new Coordinate(3.0, 4.0), new Coordinate(1.0, 2.0) }));

            Assert.AreEqual(495991521, polygon.GetHashCode());
        }