Ejemplo n.º 1
0
        public void LearningTestSimpleSetWithoutBoxing()
        {
            var memoryUsageInfo = new MemoryUsageInfo();

            memoryUsageInfo.Refresh();

            TestContainsWithoutBoxing(1000000);
            memoryUsageInfo.Refresh();
            Console.WriteLine(@"Memory usage: {0}", memoryUsageInfo);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            memoryUsageInfo.Refresh();
            Console.WriteLine(@"Memory usage after GC: {0}", memoryUsageInfo);
        }
Ejemplo n.º 2
0
        public void LearningTestSimpleSetWithBoxing()
        {
            var memoryUsageInfo = new MemoryUsageInfo();

            memoryUsageInfo.Refresh();

            TestContainsWithBoxing(1000000);

            memoryUsageInfo.Refresh();
            Console.WriteLine(@"Memory usage: {0}", memoryUsageInfo);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            memoryUsageInfo.Refresh();
            Console.WriteLine(@"Memory usage after GC: {0}", memoryUsageInfo);

            // for 10'000'000 keys:
            // --> boxing makes the contains test about 2x slower (773ms instead of 334ms),
            //     and it uses much more memory (380 mb instead of 20 mb)
        }
Ejemplo n.º 3
0
        public void CanCreateUnionWithPointsAndPolylinesFastEnough()
        {
            var overall = new MemoryUsageInfo();

            for (int i = 0; i < 5; i++)
            {
                CanCreateUnionWithPointsAndPolylinesFastEnoughCore();
                GC.Collect();
            }

            overall.Refresh();
            Console.WriteLine(@"overall: {0}", overall);
        }
        private static void GetFeaturesInLoop(
            int count,
            [NotNull] Func <IFeatureClass, int, IFeature> getFeatureMethod)
        {
            IFeatureWorkspace featureWorkspace =
                (IFeatureWorkspace)TestUtils.OpenSDEWorkspaceOracle();

            IFeatureClass featureClass =
                featureWorkspace.OpenFeatureClass("TOPGIS_TLM.TLM_DTM_MASSENPUNKTE");

            IList <int> oids = GetFeatureIDs(featureClass, count);

            var watch       = new Stopwatch();
            var memoryUsage = new MemoryUsageInfo();

            memoryUsage.Refresh();
            watch.Start();

            IGdbTransaction gdbTransaction = new GdbTransaction();

            gdbTransaction.Execute(
                (IWorkspace)featureWorkspace,
                delegate
            {
                foreach (int oid in oids)
                {
                    IFeature feature = getFeatureMethod(featureClass, oid);

                    ComUtils.ReleaseComObject(feature);
                }

                memoryUsage.Refresh();
                watch.Stop();

                Console.WriteLine("Features read: {0}", oids.Count);
                Console.WriteLine("Memory usage: {0}", memoryUsage);
                Console.WriteLine("Elapsed: {0:N0} ms", watch.ElapsedMilliseconds);
            }, "test");
        }
Ejemplo n.º 5
0
        private static void CanCreateUnionWithPointsAndPolylinesFastEnoughCore()
        {
            var input = new List <IGeometry>();

            for (int i = 0; i < 100; i++)
            {
                input.Add(GeometryFactory.CreatePoint(100 * i, 100 * i));
            }

            double xmin = 0;

            for (int i = 0; i < 1000; i++)
            {
                xmin = xmin + 100;
                double xmax = xmin + 100;
                input.Add(GeometryFactory.CreatePolyline(xmin, 100, xmax, 100));
            }

            var watch = new Stopwatch();

            watch.Start();

            var memoryInfo = new MemoryUsageInfo();

            const double expansionDistance = 10;
            IGeometry    union             = GeometryFactory.CreateUnion(input, expansionDistance);

            GC.Collect();

            watch.Stop();
            memoryInfo.Refresh();
            Console.WriteLine(memoryInfo);
            Console.WriteLine(@"{0:N2} ms", watch.ElapsedMilliseconds);

            Assert.AreEqual(esriGeometryType.esriGeometryPolyline, union.GeometryType);
        }
Ejemplo n.º 6
0
        internal static IKeySet ReadKeySet([NotNull] ITable table,
                                           [NotNull] string keyField,
                                           [CanBeNull] string whereClause,
                                           esriFieldType keyFieldType,
                                           int keyFieldIndex)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNullOrEmpty(keyField, nameof(keyField));

            Stopwatch       watch       = null;
            MemoryUsageInfo memoryUsage = null;

            if (_msg.IsVerboseDebugEnabled)
            {
                watch       = _msg.DebugStartTiming();
                memoryUsage = new MemoryUsageInfo();
                memoryUsage.Refresh();
            }

            IKeySet result = CreateKeySet(keyFieldType);

            var queryFilter = new QueryFilterClass
            {
                SubFields   = keyField,
                WhereClause = whereClause
            };
            string tableName = DatasetUtils.GetName(table);

            const bool recycle = true;

            foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, recycle))
            {
                object key = row.Value[keyFieldIndex];

                if (key == DBNull.Value || key == null)
                {
                    continue;
                }

                // TODO handle errors (e.g. invalid guid strings)
                bool added = result.Add(key);

                if (!added)
                {
                    _msg.VerboseDebugFormat(
                        "Ignored duplicate key found in field '{0}' in table '{1}': {2}",
                        keyField, tableName, key);
                }
            }

            if (watch != null)
            {
                _msg.DebugStopTiming(watch,
                                     "Reading {0:N0} {1} keys from field '{2}' in table '{3}'",
                                     result.Count, keyFieldType, keyField,
                                     DatasetUtils.GetName(table));
                _msg.DebugFormat("Memory usage of keys: {0}", memoryUsage);
            }

            return(result);
        }
Ejemplo n.º 7
0
        internal static ITupleKeySet ReadTupleKeySet(
            [NotNull] ITable table,
            [NotNull] ICollection <string> keyFields,
            [CanBeNull] string whereClause,
            [NotNull] IList <esriFieldType> keyFieldTypes,
            [NotNull] IList <int> keyFieldIndices)
        {
            Assert.ArgumentNotNull(table, nameof(table));
            Assert.ArgumentNotNull(keyFields, nameof(keyFields));
            Assert.ArgumentNotNull(keyFieldTypes, nameof(keyFieldTypes));
            Assert.ArgumentNotNull(keyFieldIndices, nameof(keyFieldIndices));

            Stopwatch       watch       = null;
            MemoryUsageInfo memoryUsage = null;

            if (_msg.IsVerboseDebugEnabled)
            {
                watch       = _msg.DebugStartTiming();
                memoryUsage = new MemoryUsageInfo();
                memoryUsage.Refresh();
            }

            var fieldIndices = new List <int>();

            foreach (string keyField in keyFields)
            {
                int fieldIndex = table.FindField(keyField);
                Assert.True(fieldIndex >= 0, "field '{0}' not found in table {1}",
                            keyField, DatasetUtils.GetName(table));
                fieldIndices.Add(fieldIndex);
            }

            ITupleKeySet result = new TupleKeySet();

            IQueryFilter queryFilter = GetQueryFilter(keyFields, whereClause);

            string keyFieldsString = StringUtils.Concatenate(keyFields, ",");
            string tableName       = DatasetUtils.GetName(table);

            const bool recycle = true;

            foreach (IRow row in GdbQueryUtils.GetRows(table, queryFilter, recycle))
            {
                Tuple tuple = ReadTuple(row, fieldIndices);

                bool added = result.Add(tuple);

                if (!added)
                {
                    _msg.DebugFormat(
                        "Ignored duplicate value combination found in fields '{0}' in table '{1}': {2}",
                        keyFieldsString, tableName, tuple);
                }
            }

            if (watch != null)
            {
                _msg.DebugStopTiming(watch,
                                     "Reading {0:N0} keys from fields '{1}' in table '{2}'",
                                     result.Count, queryFilter.SubFields,
                                     DatasetUtils.GetName(table));
                _msg.DebugFormat("Memory usage of keys: {0}", memoryUsage);
            }

            return(result);
        }
Ejemplo n.º 8
0
        public void CompareSpatialIndexPerformance()
        {
            const int pointCount = 100000;

            Linestring linestring1 =
                new Linestring(CreateRandomPoints(pointCount, 2600000, 1200000, 400));

            Linestring linestring2 =
                new Linestring(CreateRandomPoints(pointCount, 2600000, 1200000, 400));

            Stopwatch watch;
            int       foundCountBoxtree;
            int       foundSpatialHash;
            int       envelopeIntersections;
            double    tolerance = 0.01;

            MemoryUsageInfo memUsageBox = new MemoryUsageInfo();

            watch = Stopwatch.StartNew();

            linestring2.SpatialIndex =
                BoxTreeSearcher <int> .CreateSpatialSearcher(linestring2);

            watch.Stop();

            Console.WriteLine(
                $"Linestring ({pointCount}) - Box tree created: {watch.ElapsedMilliseconds}ms. PB: {memUsageBox.Refresh().PrivateBytesDelta:N0}");

            watch                 = Stopwatch.StartNew();
            foundCountBoxtree     = 0;
            envelopeIntersections = 0;
            foreach (Line3D line3D in linestring1)
            {
                int foundInEnv = linestring2.FindSegments(
                    line3D.XMin, line3D.YMin, line3D.XMax,
                    line3D.YMax, tolerance).Count();

                if (foundInEnv > 0)
                {
                    envelopeIntersections++;
                }

                foundCountBoxtree += foundInEnv;
            }

            watch.Stop();

            Console.WriteLine(
                $"Linestring ({pointCount}) - Box tree ({foundCountBoxtree} segments found): {watch.ElapsedMilliseconds}ms");

            MemoryUsageInfo memUsageHash = new MemoryUsageInfo();

            watch = Stopwatch.StartNew();

            linestring2.SpatialIndex = CreateSpatialHash(linestring2);

            watch.Stop();
            Console.WriteLine(
                $"Linestring ({pointCount}) - spatial hash created: {watch.ElapsedMilliseconds}ms. PB: {memUsageHash.Refresh().PrivateBytesDelta:N0}");

            watch                 = Stopwatch.StartNew();
            foundSpatialHash      = 0;
            envelopeIntersections = 0;
            foreach (Line3D line3D in linestring1)
            {
                int foundInEnv = linestring2.FindSegments(
                    line3D.XMin, line3D.YMin, line3D.XMax,
                    line3D.YMax, tolerance).Count();

                if (foundInEnv > 0)
                {
                    envelopeIntersections++;
                }

                foundSpatialHash += foundInEnv;
            }

            watch.Stop();

            Console.WriteLine(
                $"Linestring ({pointCount}) - Spatial hash ({foundSpatialHash} segments found): {watch.ElapsedMilliseconds}ms");

            Assert.AreEqual(foundCountBoxtree, foundSpatialHash);

            MultiPolycurve poly2 = new MultiPolycurve(new List <Linestring> {
                linestring2
            });

            memUsageHash.Refresh();
            watch = Stopwatch.StartNew();

            poly2.SpatialIndex =
                SpatialHashSearcher <SegmentIndex> .CreateSpatialSearcher(poly2);

            watch.Stop();

            Console.WriteLine(
                $"Linestring ({pointCount}) - spatial hash (using multi-part index) created: {watch.ElapsedMilliseconds}ms. PB: {memUsageHash.Refresh().PrivateBytesDelta:N0}");

            watch                 = Stopwatch.StartNew();
            foundSpatialHash      = 0;
            envelopeIntersections = 0;
            foreach (Line3D line3D in linestring1)
            {
                int foundInEnv = poly2.FindSegments(
                    line3D.XMin, line3D.YMin, line3D.XMax,
                    line3D.YMax, tolerance).Count();

                if (foundInEnv > 0)
                {
                    envelopeIntersections++;
                }

                foundSpatialHash += foundInEnv;
            }

            watch.Stop();

            Console.WriteLine(
                $"Linestring ({pointCount}) - Spatial hash on poly ({foundSpatialHash} segments found): {watch.ElapsedMilliseconds}ms");
            Assert.AreEqual(foundCountBoxtree, foundSpatialHash);
        }
Ejemplo n.º 9
0
        private static ISpatialSearcher <int> CreateSpatialHash(Linestring linestring)
        {
            MemoryUsageInfo memUsageHash = new MemoryUsageInfo();
            var             watch        = Stopwatch.StartNew();

            var gridSize =
                SpatialHashSearcher <int> .EstimateOptimalGridSize(new[] { linestring });

            watch.Stop();
            Console.WriteLine(
                $"Linestring ({linestring.PointCount}) - Spatial hash: calculated grid size: {watch.ElapsedMilliseconds}ms. PB: {memUsageHash.Refresh().PrivateBytesDelta:N0}");

            watch = Stopwatch.StartNew();

            var result =
                SpatialHashSearcher <int> .CreateSpatialSearcher(linestring, gridSize);

            watch.Stop();
            Console.WriteLine(
                $"Linestring ({linestring.PointCount}) - Spatial hash created: {watch.ElapsedMilliseconds}ms. PB: {memUsageHash.Refresh().PrivateBytesDelta:N0}");

            return(result);
        }