コード例 #1
0
			internal Version(Version prev)
			{
				this.provider = prev.provider;
				this.id = unchecked( prev.id + 1 );
			}
コード例 #2
0
			internal Version(TextSourceVersionProvider provider)
			{
				this.provider = provider;
			}
コード例 #3
0
 internal Version(TextSourceVersionProvider provider)
 {
     this.provider = provider;
 }
コード例 #4
0
 internal Version(Version prev)
 {
     this.provider = prev.provider;
     this.id       = unchecked (prev.id + 1);
 }
コード例 #5
0
        public static void Run(ITextSource originalXmlFile)
        {
            int seed;
            lock (sharedRnd) {
                seed = sharedRnd.Next();
            }
            Console.WriteLine(seed);
            Random rnd = new Random(seed);

            AXmlParser parser = new AXmlParser();
            StringBuilder b = new StringBuilder(originalXmlFile.Text);
            IncrementalParserState parserState = null;
            var versionProvider = new TextSourceVersionProvider();
            int totalCharactersParsed = 0;
            int totalCharactersChanged = originalXmlFile.TextLength;
            TimeSpan incrementalParseTime = TimeSpan.Zero;
            TimeSpan nonIncrementalParseTime = TimeSpan.Zero;
            Stopwatch w = new Stopwatch();
            for (int iteration = 0; iteration < 100; iteration++) {
                totalCharactersParsed += b.Length;
                var textSource = new StringTextSource(b.ToString(), versionProvider.CurrentVersion);
                w.Restart();
                var incrementalResult = parser.ParseIncremental(parserState, textSource, out parserState);
                w.Stop();
                incrementalParseTime += w.Elapsed;
                w.Restart();
                var nonIncrementalResult = parser.Parse(textSource);
                w.Stop();
                nonIncrementalParseTime += w.Elapsed;
                CompareResults(incrementalResult, nonIncrementalResult);

                incrementalResult.AcceptVisitor(new ValidationVisitor(textSource));

                // Randomly mutate the file:

                List<TextChangeEventArgs> changes = new List<TextChangeEventArgs>();
                int modifications = rnd.Next(0, 25);
                int offset = 0;
                for (int i = 0; i < modifications; i++) {
                    if (i == 0 || rnd.Next(0, 10) == 0)
                        offset = rnd.Next(0, b.Length);
                    else
                        offset += rnd.Next(0, Math.Min(10, b.Length - offset));
                    int originalOffset = rnd.Next(0, originalXmlFile.TextLength);
                    int insertionLength;
                    int removalLength;
                    switch (rnd.Next(0, 21) / 10) {
                        case 0:
                            removalLength = 0;
                            insertionLength = rnd.Next(0, Math.Min(50, originalXmlFile.TextLength - originalOffset));
                            break;
                        case 1:
                            removalLength = rnd.Next(0, Math.Min(20, b.Length - offset));
                            insertionLength = rnd.Next(0, Math.Min(20, originalXmlFile.TextLength - originalOffset));
                            break;
                        default:
                            removalLength = rnd.Next(0, b.Length - offset);
                            insertionLength = rnd.Next(0, originalXmlFile.TextLength - originalOffset);
                            break;
                    }
                    string removedText = b.ToString(offset, removalLength);
                    b.Remove(offset, removalLength);
                    string insertedText = originalXmlFile.GetText(originalOffset, insertionLength);
                    b.Insert(offset, insertedText);
                    versionProvider.AppendChange(new TextChangeEventArgs(offset, removedText, insertedText));
                    totalCharactersChanged += insertionLength;
                }
            }
            Console.WriteLine("Incremental parse time:     " + incrementalParseTime + " for " + totalCharactersChanged + " characters changed");
            Console.WriteLine("Non-Incremental parse time: " + nonIncrementalParseTime + " for " + totalCharactersParsed + " characters");
        }