Пример #1
0
        public void UserStreamParserPerformanceTest()
        {
            var workingset = Environment.WorkingSet;
            var parser = new JsonStringParser();
            // pre-work
            for (var i = 0; i < 100; i++)
            {
                foreach (var elem in TweetSamples.GetStreamSampleElements())
                {
                    parser.Parse(elem);
                }
            }

            var source = new CancellationTokenSource();
            var handler = new PseudoStreamHandler();
            var received = 0;
            source.CancelAfter(TimeSpan.FromSeconds(10));
            foreach (var content in TweetSamples.GetStreamSamples())
            {
                if (source.IsCancellationRequested) break;
                received++;
                UserStreamParser.ParseStreamLine(parser, content, handler);
            }
            var wsa = Environment.WorkingSet;
            TestContext.WriteLine("received: {0}", received);
            TestContext.WriteLine("handler: statuses: {0} / events: {1}", handler.ReceivedStatuses, handler.ReceivedEvents);
            TestContext.WriteLine("cache: {0} / {1}", parser.CacheCount(), parser.ALQCount());
            TestContext.WriteLine("workingset delta: {0}", wsa - workingset);
        }
Пример #2
0
 public static void ParseStreamLine(JsonStringParser parser, string line, IStreamHandler handler)
 {
     try
     {
         var element = parser.Parse(line);
         ParseStreamLine(element, handler);
     }
     catch (Exception ex)
     {
         handler.OnException(new StreamParseException(
             "JSON parse failed.", line, ex));
     }
 }