Exemple #1
0
        public void TestSentenceFactoryPerformance()
        {
            var factory = new SentenceFactory {
                IsCrcEnabled = true
            };

            var watch     = Stopwatch.StartNew();
            var sentences = factory.ProcessStream(m_nmeaData).ToArray();

            watch.Stop();

            Console.WriteLine(@"Data:{0} bytes", m_nmeaData.Length);
            Console.WriteLine(@"Nmea sentences:{0}", sentences.Length);
            Console.WriteLine(@"Time:{0} ms", watch.ElapsedMilliseconds);
            Console.WriteLine(@"Time per sentence:{0} ms", (double)watch.ElapsedMilliseconds / sentences.Length);

            Assert.LessOrEqual((double)watch.ElapsedMilliseconds / sentences.Length, 1);
        }
Exemple #2
0
        public void TestAisMessageFactoryPerformance()
        {
            var factory = new SentenceFactory {
                IsCrcEnabled = true
            };
            var sentences       = factory.ProcessStream(m_nmeaData);
            var messageFactory  = new CommonAisMessageFactory();
            var skippedMessages = 0;
            var totalMessages   = 0;
            var totalSentences  = 0;

            var statisticsSupported    = new Dictionary <int, int>();
            var statisticsNotSupported = new Dictionary <int, int>();
            var maxTime     = 0L;
            var maxTimeType = 0;

            var watch       = Stopwatch.StartNew();
            var watchSingle = Stopwatch.StartNew();

            foreach (var sentence in sentences)
            {
                totalSentences++;
                watchSingle.Restart();
                bool fragmented;
                var  message1 = messageFactory.CreateAisMessage(sentence, out fragmented);
                watchSingle.Stop();

                if (watchSingle.ElapsedMilliseconds > maxTime)
                {
                    maxTime     = watchSingle.ElapsedMilliseconds;
                    maxTimeType = message1 != null ? message1.Type : 0;
                }

                if (fragmented)
                {
                    continue;
                }

                if (message1 is UnsupportedMessage)
                {
                    if (!statisticsNotSupported.ContainsKey(message1.Type))
                    {
                        statisticsNotSupported.Add(message1.Type, 0);
                    }

                    statisticsNotSupported[message1.Type] = ++statisticsNotSupported[message1.Type];
                    skippedMessages++;
                    continue;
                }

                if (!statisticsSupported.ContainsKey(message1.Type))
                {
                    statisticsSupported.Add(message1.Type, 0);
                }

                statisticsSupported[message1.Type] = ++statisticsSupported[message1.Type];
                totalMessages++;
            }
            watch.Stop();

            Console.WriteLine(@"Data:{0} bytes", m_nmeaData.Length);
            Console.WriteLine(@"Nmea sentences:{0}", totalSentences);


            Console.WriteLine(@"Ais messages:{0}", totalMessages);
            Console.WriteLine(@"Skipped messages:{0}", skippedMessages);
            Console.WriteLine(@"Processed messages:{0}", totalMessages - skippedMessages);
            Console.WriteLine(@"Time:{0} ms", watch.ElapsedMilliseconds);
            Console.WriteLine(@"Time per processed message:{0} ms", (double)watch.ElapsedMilliseconds / (totalMessages - skippedMessages));
            Console.WriteLine(@"Max time per message:{0}", maxTime);
            Console.WriteLine(@"Max time message type:{0}", maxTimeType);

            Console.WriteLine(@"Supported:");
            foreach (var kv in statisticsSupported)
            {
                Console.WriteLine(@"Type:{0} count:{1}", kv.Key, kv.Value);
            }

            Console.WriteLine(@"Not supported:");
            foreach (var kv in statisticsNotSupported)
            {
                Console.WriteLine(@"Type:{0} count:{1}", kv.Key, kv.Value);
            }
        }