Important alert: (current site time 7/15/2013 7:38:35 AM EDT)
 

VB icon

[ A Simple] code execution time tests

Email
Submitted on: 10/6/2003 6:18:23 PM
By: lonetron 
Level: Advanced
User Rating: By 1 Users
Compatibility: C#
Views: 23404
author picture
(About the author)
 
     Paste this into your C# code to test how long a portion of your code takes to execute. The number of milliseconds is appended to C:\TimeTest.txt

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: [ A Simple] code execution time tests
// Description:Paste this into your C# code to test how 
long a portion of your code takes to execute. 
The number of milliseconds is appended to C:\TimeTest.txt
// By: lonetron
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1620&lngWId=10//for details.//**************************************

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace InCodeTimeTest{
	public class CInCodeTimeTest : System.Windows.Forms.Form{
		#region ConstructAndDispose
		private System.ComponentModel.Container components = null;
		public CInCodeTimeTest(){
			InitializeComponent();
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing ){
				if (components != null) {
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// CInCodeTimeTest
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Name = "CInCodeTimeTest";
			this.Text = "In Code Time Test";
			this.Load += new System.EventHandler(this.CInCodeTimeTest_Load);
		}
		#endregion
		#region Main
		[STAThread]
		static void Main() 
		{
			Application.Run(new CInCodeTimeTest());
		}
		#endregion Main
		private void CInCodeTimeTest_Load(object sender, System.EventArgs e)
		{
			/*
				--------------------------------
				Simple code execution time tests
				--------------------------------
				Paste this into your C# code to test how 
				long a portion of your code takes to execute. 
				The number of milliseconds is appended to C:\TimeTest.txt
			_________________________________________________________________________
				|This simple solution was brought to you by the P2B Consortium. |
				|“Create your very own artificial intelligence chat-bot now!”|
				|http://www.p2bconsortium.com/ |
				| |
				|Create, deploy and test artificial intelligence chat-bot |
				|now with Rapid Bot Trainer: http://www.p2bconsortium.com/sss/rbt.aspx |
				| |
				|Create, deploy and test artificial intelligence chat-bot |
				|now with ANY IRC CLIENT and no downloads:|
				|http://www.p2bconsortium.com/stork.html |
				| |
				|Create, test and deploy an artificial intelligence chat-bot|
				|to ANY ONLINE CHATROOM with the TANU public API web methods:|
				|http://www.p2bconsortium.com/Simple%20State%20Server%20Tutorial.htm|
				|http://www.p2bconsortium.com/sss/sss.asmx|
				|_________________________________________________________________________|
			*/
			//Start Copying Here
			System.DateTime tm = System.DateTime.Now;
			//Stop Copying Here, Paste this before the code that you need to time test.
			System.Threading.Thread.Sleep(1000);
			//Start Copying Here
			System.DateTime tma = System.DateTime.Now;
			System.IO.StreamWriter sw = System.IO.File.AppendText("C:\\TimeTest.txt");
			sw.WriteLine((((((tma.Hour * (24 * 60 * 1000)) + (tma.Minute * (60 * 1000))) + (tma.Second * 1000)) + tma.Millisecond) - ((((tm.Hour * (24 * 60 * 1000)) + (tm.Minute * (60 * 1000))) + (tm.Second * 1000)) + tm.Millisecond)));
			sw.Flush();
			//Stop Copying Here
		}
	}
}


Other 9 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/26/2004 3:22:53 AM

'TimeSpan' is an easier way to calculate the timespan...
(If this comment was disrespectful, please report it.)

 
5/21/2005 7:24:53 AM

Thanks for these all
(If this comment was disrespectful, please report it.)

 
3/16/2006 4:11:23 AMTommy Baron

Getting then assigning to variables time values takes time, the fastest and easiest way would be to get the system tick count (Environment.TickCount) before and after and then subtract the two to find the difference.
(If this comment was disrespectful, please report it.)

 
3/29/2007 4:15:51 AMsusheel

good code

(If this comment was disrespectful, please report it.)

 
6/6/2007 5:03:59 PMthekingdom

what!!!?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.