static void Main(string[] args)
		{
			PerfTest perf = new PerfTest();
			int repeat = 1000;
			perf.Start();
			XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource));
			//XmlDocument doc = new XmlDocument();
			//doc.Load("test/northwind.xml");
			Console.WriteLine("Loading XML document: {0, 6:f2} ms", perf.Stop());
			XPathNavigator nav = doc.CreateNavigator();      
			XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress");
      
			Console.WriteLine("Regular selection, warming...");
			SelectNodes(nav, repeat, perf, expr);
			Console.WriteLine("Regular selection, testing...");
			SelectNodes(nav, repeat, perf, expr);
   
      
			perf.Start();
			IndexingXPathNavigator inav = new IndexingXPathNavigator(
				doc.CreateNavigator());
			Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", perf.Stop());
			perf.Start();
			inav.AddKey("orderKey", "OrderIDs/Item", "OrderID");
			Console.WriteLine("Adding keys: {0, 6:f2} ms", perf.Stop());    
			XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress");
			perf.Start();
			inav.BuildIndexes();
			Console.WriteLine("Indexing: {0, 6:f2} ms", perf.Stop());    
      
			Console.WriteLine("Indexed selection, warming...");
			SelectIndexedNodes(inav, repeat, perf, expr2);
			Console.WriteLine("Indexed selection, testing...");
			SelectIndexedNodes(inav, repeat, perf, expr2);      
		}
		private static void SelectIndexedNodes(XPathNavigator nav, int repeat, PerfTest perf, XPathExpression expr) 
		{
			int counter = 0;
			perf.Start();
			for (int i=0; i<repeat; i++) 
			{
				XPathNodeIterator ni =  nav.Select(expr);
				while (ni.MoveNext())
					counter++;
			}
			Console.WriteLine("Indexed selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat, 
				perf.Stop(), counter);
		}
        static void Main(string[] args)
        {
            PerfTest perf   = new PerfTest();
            int      repeat = 1000;

            perf.Start();
            XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource));

            //XmlDocument doc = new XmlDocument();
            //doc.Load("test/northwind.xml");
            Console.WriteLine("Loading XML document: {0, 6:f2} ms", perf.Stop());
            XPathNavigator  nav  = doc.CreateNavigator();
            XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress");

            Console.WriteLine("Regular selection, warming...");
            SelectNodes(nav, repeat, perf, expr);
            Console.WriteLine("Regular selection, testing...");
            SelectNodes(nav, repeat, perf, expr);


            perf.Start();
            IndexingXPathNavigator inav = new IndexingXPathNavigator(
                doc.CreateNavigator());

            Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", perf.Stop());
            perf.Start();
            inav.AddKey("orderKey", "OrderIDs/Item", "OrderID");
            Console.WriteLine("Adding keys: {0, 6:f2} ms", perf.Stop());
            XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress");

            perf.Start();
            inav.BuildIndexes();
            Console.WriteLine("Indexing: {0, 6:f2} ms", perf.Stop());

            Console.WriteLine("Indexed selection, warming...");
            SelectIndexedNodes(inav, repeat, perf, expr2);
            Console.WriteLine("Indexed selection, testing...");
            SelectIndexedNodes(inav, repeat, perf, expr2);
        }
        private static void SelectIndexedNodes(XPathNavigator nav, int repeat, PerfTest perf, XPathExpression expr)
        {
            int counter = 0;

            perf.Start();
            for (int i = 0; i < repeat; i++)
            {
                XPathNodeIterator ni = nav.Select(expr);
                while (ni.MoveNext())
                {
                    counter++;
                }
            }
            Console.WriteLine("Indexed selection: {0} times, total time {1, 6:f2} ms, {2} nodes selected", repeat,
                              perf.Stop(), counter);
        }
Exemplo n.º 5
0
		public void SubtreeSpeed() 
		{
			XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.LibraryResource));
			XPathNavigator nav = xdoc.CreateNavigator();
			XmlDocument doc = new XmlDocument();
			doc.Load(Globals.GetResource(Globals.LibraryResource));

			XslTransform xslt = new XslTransform();
			xslt.Load(new XmlTextReader(
				Globals.GetResource(this.GetType().Namespace + ".print_root.xsl")));

			PerfTest pt = new PerfTest();

			// Warmup
			MemoryStream stmdom = new MemoryStream();
			XmlDocument wd = new XmlDocument(); 
			wd.LoadXml(doc.DocumentElement.FirstChild.OuterXml);
			xslt.Transform(wd, null, stmdom, null);
			MemoryStream stmxpath = new MemoryStream();
			nav.MoveToRoot();
			nav.MoveToFirstChild();
			nav.MoveToFirstChild();
			xslt.Transform(new SubtreeeXPathNavigator(nav), null, stmxpath, null);
			nav = doc.CreateNavigator();

			int count = 10;
			float dom = 0;
			float xpath = 0;

			for (int i = 0; i < count; i++)
			{
				GC.Collect();
				System.Threading.Thread.Sleep(1000);

				stmdom = new MemoryStream();

				pt.Start();

				// Create a new document for each child
				foreach (XmlNode testNode in doc.DocumentElement.ChildNodes)
				{
					XmlDocument tmpDoc = new XmlDocument(); 
					tmpDoc.LoadXml(testNode.OuterXml);

					// Transform the subset.
					xslt.Transform(tmpDoc, null, stmdom, null);
				}

				dom += pt.Stop();
                
				GC.Collect();
				System.Threading.Thread.Sleep(1000);
				
				stmxpath = new MemoryStream();

				XPathExpression expr = nav.Compile("/library/book");

				pt.Start();
				XPathNodeIterator books = nav.Select(expr);
				while (books.MoveNext())
				{
					xslt.Transform(new SubtreeeXPathNavigator(books.Current), null, stmxpath, null);
				}
				
				xpath += pt.Stop();
			}

			Console.WriteLine("XmlDocument transformation: {0}", dom / count);
			Console.WriteLine("SubtreeXPathNavigator transformation: {0}", xpath / count);

			stmdom.Position = 0;
			stmxpath.Position = 0;

			Console.WriteLine(new StreamReader(stmdom).ReadToEnd());
			Console.WriteLine(new string('*', 100));
			Console.WriteLine(new string('*', 100));
			Console.WriteLine(new StreamReader(stmxpath).ReadToEnd());
		}
Exemplo n.º 6
0
        public void SubtreeSpeed()
        {
            XPathDocument  xdoc = new XPathDocument(Globals.GetResource(Globals.LibraryResource));
            XPathNavigator nav  = xdoc.CreateNavigator();
            XmlDocument    doc  = new XmlDocument();

            doc.Load(Globals.GetResource(Globals.LibraryResource));

            XslTransform xslt = new XslTransform();

            xslt.Load(new XmlTextReader(
                          Globals.GetResource(this.GetType().Namespace + ".print_root.xsl")));

            PerfTest pt = new PerfTest();

            // Warmup
            MemoryStream stmdom = new MemoryStream();
            XmlDocument  wd     = new XmlDocument();

            wd.LoadXml(doc.DocumentElement.FirstChild.OuterXml);
            xslt.Transform(wd, null, stmdom, null);
            MemoryStream stmxpath = new MemoryStream();

            nav.MoveToRoot();
            nav.MoveToFirstChild();
            nav.MoveToFirstChild();
            xslt.Transform(new SubtreeeXPathNavigator(nav), null, stmxpath, null);
            nav = doc.CreateNavigator();

            int   count = 10;
            float dom   = 0;
            float xpath = 0;

            for (int i = 0; i < count; i++)
            {
                GC.Collect();
                System.Threading.Thread.Sleep(1000);

                stmdom = new MemoryStream();

                pt.Start();

                // Create a new document for each child
                foreach (XmlNode testNode in doc.DocumentElement.ChildNodes)
                {
                    XmlDocument tmpDoc = new XmlDocument();
                    tmpDoc.LoadXml(testNode.OuterXml);

                    // Transform the subset.
                    xslt.Transform(tmpDoc, null, stmdom, null);
                }

                dom += pt.Stop();

                GC.Collect();
                System.Threading.Thread.Sleep(1000);

                stmxpath = new MemoryStream();

                XPathExpression expr = nav.Compile("/library/book");

                pt.Start();
                XPathNodeIterator books = nav.Select(expr);
                while (books.MoveNext())
                {
                    xslt.Transform(new SubtreeeXPathNavigator(books.Current), null, stmxpath, null);
                }

                xpath += pt.Stop();
            }

            Console.WriteLine("XmlDocument transformation: {0}", dom / count);
            Console.WriteLine("SubtreeXPathNavigator transformation: {0}", xpath / count);

            stmdom.Position   = 0;
            stmxpath.Position = 0;

            Console.WriteLine(new StreamReader(stmdom).ReadToEnd());
            Console.WriteLine(new string('*', 100));
            Console.WriteLine(new string('*', 100));
            Console.WriteLine(new StreamReader(stmxpath).ReadToEnd());
        }
Exemplo n.º 7
0
        public void FullDocValidation()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(Globals.GetResource(Globals.PubsNsResource));
            XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.PubsNsResource));

            XmlSchema xsd = XmlSchema.Read(
                Globals.GetResource(Globals.PubsNsSchemaResource), null);

            xsd.Compile(null);

            // Warmup
            XmlReader r = new XmlValidatingReader(
                new XmlTextReader(new StringReader(doc.OuterXml)));

            while (r.Read())
            {
            }
            r = new XmlValidatingReader(
                new XPathNavigatorReader(doc.CreateNavigator()));
            while (r.Read())
            {
            }
            r = new XmlValidatingReader(
                new XPathNavigatorReader(xdoc.CreateNavigator()));
            while (r.Read())
            {
            }

            PerfTest pt = new PerfTest();

            int   count    = 10;
            float xml      = 0;
            float xpath    = 0;
            float xdoctime = 0;

            for (int i = 0; i < count; i++)
            {
                pt.Start();

                r = new XmlValidatingReader(
                    new XmlTextReader(new StringReader(doc.OuterXml)));
                while (r.Read())
                {
                }

                xml += pt.Stop();

                pt.Start();

                r = new XmlValidatingReader(
                    new XPathNavigatorReader(doc.CreateNavigator()));
                while (r.Read())
                {
                }

                xpath += pt.Stop();

                pt.Start();

                r = new XmlValidatingReader(
                    new XPathNavigatorReader(xdoc.CreateNavigator()));
                while (r.Read())
                {
                }

                xdoctime += pt.Stop();
            }

            Console.WriteLine("OuterXml validation: {0}", xml / count);
            Console.WriteLine("XPathNavigatorReader validation: {0}", xpath / count);
            Console.WriteLine("XPathDocument/Reader validation: {0}", xdoctime / count);
        }
Exemplo n.º 8
0
        public void TrasformItems()
        {
            string xml = @"<library>
  <book genre='novel' ISBN='1-861001-57-5'>
     <title>Pride And Prejudice</title>
  </book>
  <book genre='novel' ISBN='1-81920-21-2'>
     <title>Hook</title>
  </book>
</library>";
            string xsl = @"<stylesheet version='1.0' xmlns='http://www.w3.org/1999/XSL/Transform' >
  <output method='text' /> 
  <template match='/'>
     <variable name='first' select='/*[1]/*[1]' />
     <variable name='second' select='/publishers/pub_id' />
     <variable name='third' select='//*[title_id=""BU2075""]' />
  </template>
</stylesheet>";

            XslTransform xslt = new XslTransform();

            xslt.Load(new XmlTextReader(new StringReader(xsl)),
                      null, this.GetType().Assembly.Evidence);

            XPathDocument wp = new XPathDocument(Globals.GetResource(Globals.PubsResource));
            XmlDocument   wd = new XmlDocument();

            wd.Load(Globals.GetResource(Globals.PubsResource));

            PerfTest p = new PerfTest();

            p.Start();

            // Load the entire doc.
            XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.PubsResource));
            // Create a new document for each child
            XPathNodeIterator books = doc.CreateNavigator().Select("/dsPubs/publishers");

            while (books.MoveNext())
            {
                XPathDocument tmpDoc = new XPathDocument(
                    new XPathNavigatorReader(books.Current));

                // Pass the document containing the node fragment
                // to the Transform method.
                xslt.Transform(tmpDoc, null, Console.Out, null);
            }

            Console.WriteLine("\nElapsed: {0}", p.Stop());

            p = new PerfTest();
            p.Start();

            // Load the entire doc.
            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(Globals.GetResource(Globals.PubsResource));
            // Create a new document containing just the node fragment.

            // Create a new document for each child
            foreach (XmlNode testNode in xdoc.SelectNodes("/dsPubs/publishers"))
            {
                XmlDocument tmpDoc = new XmlDocument();
                tmpDoc.LoadXml(testNode.OuterXml);
                // Pass the document containing the node fragment
                // to the Transform method.
                xslt.Transform(tmpDoc, null, Console.Out, null);
            }

            Console.WriteLine("\nElapsed: {0}", p.Stop());
        }
Exemplo n.º 9
0
		public void FullDocValidation()
		{
			XmlDocument doc = new XmlDocument();
			doc.Load(Globals.GetResource(Globals.PubsNsResource));
			XPathDocument xdoc = new XPathDocument(Globals.GetResource(Globals.PubsNsResource));

			XmlSchema xsd = XmlSchema.Read(
				Globals.GetResource(Globals.PubsNsSchemaResource), null);
			xsd.Compile(null);

			// Warmup
			XmlReader r = new XmlValidatingReader(
				new XmlTextReader(new StringReader(doc.OuterXml)));
			while (r.Read()) {}
			r = new XmlValidatingReader(
				new XPathNavigatorReader(doc.CreateNavigator()));
			while (r.Read()) {}
			r = new XmlValidatingReader(
				new XPathNavigatorReader(xdoc.CreateNavigator()));
			while (r.Read()) {}

			PerfTest pt = new PerfTest();

			int count = 10;
			float xml = 0;
			float xpath = 0;
			float xdoctime = 0;

			for (int i = 0; i < count; i++)
			{
				pt.Start();

				r = new XmlValidatingReader(
					new XmlTextReader(new StringReader(doc.OuterXml)));
				while (r.Read()) {}

				xml += pt.Stop();
             	
				pt.Start();

				r = new XmlValidatingReader(
					new XPathNavigatorReader(doc.CreateNavigator()));
				while (r.Read()) {}
				
				xpath += pt.Stop();

				pt.Start();

				r = new XmlValidatingReader(
					new XPathNavigatorReader(xdoc.CreateNavigator()));
				while (r.Read()) {}

				xdoctime += pt.Stop();
			}

			Console.WriteLine("OuterXml validation: {0}", xml / count);
			Console.WriteLine("XPathNavigatorReader validation: {0}", xpath / count);
			Console.WriteLine("XPathDocument/Reader validation: {0}", xdoctime / count);
		}
Exemplo n.º 10
0
		public void TrasformItems()
		{
			string xml = @"<library>
  <book genre='novel' ISBN='1-861001-57-5'>
     <title>Pride And Prejudice</title>
  </book>
  <book genre='novel' ISBN='1-81920-21-2'>
     <title>Hook</title>
  </book>
</library>";
			string xsl = @"<stylesheet version='1.0' xmlns='http://www.w3.org/1999/XSL/Transform' >
  <output method='text' /> 
  <template match='/'>
     <variable name='first' select='/*[1]/*[1]' />
     <variable name='second' select='/publishers/pub_id' />
     <variable name='third' select='//*[title_id=""BU2075""]' />
  </template>
</stylesheet>";

			XslTransform xslt = new XslTransform();     
			xslt.Load(new XmlTextReader(new StringReader(xsl)), 
				null, this.GetType().Assembly.Evidence);

			XPathDocument wp = new XPathDocument(Globals.GetResource(Globals.PubsResource));
			XmlDocument wd = new XmlDocument();
			wd.Load(Globals.GetResource(Globals.PubsResource));

			PerfTest p = new PerfTest();
			p.Start();

			// Load the entire doc.
			XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.PubsResource));
			// Create a new document for each child
			XPathNodeIterator books = doc.CreateNavigator().Select("/dsPubs/publishers");
			while (books.MoveNext())
			{
				XPathDocument tmpDoc = new XPathDocument(
					new XPathNavigatorReader(books.Current)); 

				// Pass the document containing the node fragment 
				// to the Transform method.
				xslt.Transform(tmpDoc, null, Console.Out, null);
			}

			Console.WriteLine("\nElapsed: {0}", p.Stop());

			p = new PerfTest();
			p.Start();

			// Load the entire doc.
			XmlDocument xdoc = new XmlDocument();
			xdoc.Load(Globals.GetResource(Globals.PubsResource));
			// Create a new document containing just the node fragment.
			
			// Create a new document for each child
			foreach (XmlNode testNode in xdoc.SelectNodes("/dsPubs/publishers"))
			{
				XmlDocument tmpDoc = new XmlDocument(); 
				tmpDoc.LoadXml(testNode.OuterXml);
				// Pass the document containing the node fragment 
				// to the Transform method.
				xslt.Transform(tmpDoc, null, Console.Out, null);
			}

			Console.WriteLine("\nElapsed: {0}", p.Stop());
		}