/// <summary>Measures the time spent executing action.</summary>
        /// <param name="name">The name.</param>
        /// <param name="repeat">Number of repetiotions.</param>
        /// <param name="action">The action.</param>
        /// <param name="size">The size.</param>
        public static void Debug(string name, int repeat, Action action, double size = 0)
        {
            var timer = new PerformanceTimer();

            using (timer.Scope())
            {
                action();
            }
            var time = timer.Elapsed / repeat;

            Console.WriteLine("{0}: {1:0.0000}ms ({2:0.00}/s)", name, time * 1000, size / time);
        }
        /// <summary>Measures the time spent executing action.</summary>
        /// <typeparam name="T">Type of result.</typeparam>
        /// <param name="name">The name.</param>
        /// <param name="repeat">Number of repetiotions.</param>
        /// <param name="action">The action.</param>
        /// <param name="size">The size.</param>
        /// <returns>Value returned by action.</returns>
        public static T Debug <T>(string name, int repeat, Func <T> action, double size = 0)
        {
            var result = default(T);
            var timer  = new PerformanceTimer();

            using (timer.Scope())
            {
                for (int i = 0; i < repeat; i++)
                {
                    result = action();
                }
            }
            var time = timer.Elapsed / repeat;

            Console.WriteLine("{0}: {1:0.0000}ms ({2:0.00}/s)", name, time * 1000, size / time);
            return(result);
        }
Beispiel #3
0
 private void LoadXmlFile()
 {
     PerformanceTimer timer = new PerformanceTimer();
     timer.Start();
     this._xmlDoc.Load(this._XmlFileName);
     timer.Stop();
     this.statusBar.Text = "Xml Document Load Time: " + timer.ElapsedTime.ToString() + " ms";
     this.btnExecuteQuery.Enabled = true;
     this.FillXmlDocument(this._xmlDoc);
 }
Beispiel #4
0
 private void btnExecuteQuery_Click(object sender, EventArgs e)
 {
     this.btnSelXPath.Enabled = false;
     this._treeResult.BeginUpdate();
     this._treeResult.Nodes.Clear();
     XmlNode documentElement = this._xmlDoc.DocumentElement;
     TreeNode node = new TreeNode(this._xmlString);
     this._treeResult.Nodes.Add(node);
     try
     {
         PerformanceTimer timer = new PerformanceTimer();
         timer.Start();
         XmlNodeList list = null;
         if (this._hasNS)
         {
             list = documentElement.SelectNodes(this.txtQuery.Text, this._nsMgr);
         }
         else
         {
             list = documentElement.SelectNodes(this.txtQuery.Text);
         }
         timer.Stop();
         this.statusBar.Text = "XPath Query -- Elapsed time: " + timer.ElapsedTime.ToString() + " ms";
         for (int i = 0; i < list.Count; i++)
         {
             this.Xml2Tree(node, list[i]);
         }
         this.isContextNode = true;
     }
     catch (XPathException exception)
     {
         MessageBox.Show("Error in XPath Query:" + exception.Message);
         this.btnSelXPath.Enabled = true;
         this.isContextNode = false;
         return;
     }
     catch (XsltException exception2)
     {
         MessageBox.Show(exception2.Message);
         this.btnSelXPath.Enabled = true;
         this.isContextNode = false;
         return;
     }
     this._treeResult.EndUpdate();
     node.Expand();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PerformanceTimerScope"/> class.
 /// </summary>
 /// <param name="timer">The timer to control.</param>
 public PerformanceTimerScope(PerformanceTimer timer)
 {
     m_Timer = timer;
     timer.Start();
 }