/*
* Copyright 2006, Dustin Metzgar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using NUnit.Framework;
using XmiCodeDomLib;
namespace XmiCodeDomLib.TestHarness
{
[TestFixture]
public class Parser
{
private void RunSpeedTest(XmiParserType parser, string docName, string filename, int numRuns)
{
Console.WriteLine("Running " + parser.ToString() + "-based parser on " + docName + ".");
DateTime startTime = DateTime.Now;
for (int i = 0; i < numRuns; i++)
{
XmiRoot root = new XmiRoot();
XmlTextReader xtr = new XmlTextReader(filename);
root.Parse(xtr, parser);
xtr.Close();
}
TimeSpan time = DateTime.Now.Subtract(startTime);
Console.WriteLine("Time (secs) : " + (time.TotalMilliseconds / 1000));
Console.WriteLine("Average (secs) : " + (time.TotalMilliseconds / (1000 * numRuns)));
}
[Test]
public void CompareParseTimes()
{
// Initialize the CodeDomParsers to get a more fair reading.
XmiParserFactory.Init();
string version10Doc = "graphics.xmi";
string version12Doc = "test10.xmi";
int numRuns = 50;
RunSpeedTest(XmiParserType.Reflection, "version 1.0 document", version10Doc, numRuns);
RunSpeedTest(XmiParserType.CodeDom, "version 1.0 document", version10Doc, numRuns);
RunSpeedTest(XmiParserType.CodeDomSwitch, "version 1.0 document", version10Doc, numRuns);
RunSpeedTest(XmiParserType.CodeDomOptimized, "version 1.0 document", version10Doc, numRuns);
RunSpeedTest(XmiParserType.Reflection, "version 1.2 document", version12Doc, numRuns);
RunSpeedTest(XmiParserType.CodeDom, "version 1.2 document", version12Doc, numRuns);
RunSpeedTest(XmiParserType.CodeDomSwitch, "version 1.2 document", version12Doc, numRuns);
RunSpeedTest(XmiParserType.CodeDomOptimized, "version 1.2 document", version12Doc, numRuns);
}
}
}