Measuring parse time

Jul 20, 2011 at 6:42 PM

Hi Roman,

While trying to work out why I am not seeing a performance difference, I have found the following that could help things along.

If we look at the following code in Parser.cs

   public ParseTree Parse(string sourceText, string fileName) {
      if (Context.Status != ParserStatus.AcceptedPartial)
        Reset(); 
      Context.SourceStream.SetText(sourceText, 0, Context.Status == ParserStatus.AcceptedPartial);
      Context.CurrentParseTree = new ParseTree(sourceText, fileName);
      Context.Status = ParserStatus.Parsing;
      int start = Environment.TickCount;
      CoreParser.Parse();
      Context.CurrentParseTree.ParseTime = Environment.TickCount - start;
      UpdateParseTreeStatus(); 
      return Context.CurrentParseTree;
    }

and we replace Environment.TickCount with a stopwatch then we get a far higher accuracy and more timing consistent result.

    public ParseTree Parse(string sourceText, string fileName) {
      if (Context.Status != ParserStatus.AcceptedPartial)
        Reset(); 
      Context.SourceStream.SetText(sourceText, 0, Context.Status == ParserStatus.AcceptedPartial);
      Context.CurrentParseTree = new ParseTree(sourceText, fileName);
      Context.Status = ParserStatus.Parsing;
      System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
    
      stopwatch.Start();
      CoreParser.Parse();
      stopwatch.Stop();
      Context.CurrentParseTree.ParseTime = stopwatch.ElapsedMilliseconds;
      UpdateParseTreeStatus(); 
      return Context.CurrentParseTree;
    }

I also changed the ParseTime to long to avoid the cast.
It doesnt make the code run any faster but at least the measured parse time is displayed more consistently!
Coordinator
Jul 20, 2011 at 6:52 PM

good catch, let's change that

thanks

Roman