Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Using system;
Using system. Collections. Generic;
Using system. text;
Using system. diagnostics;
Using system. Text. regularexpressions;
Namespace isnumbertest{/// /// Comparison of several methods to verify whether all strings are numeric/// Class Program{Static void main (string [] ARGs){Stopwatch SW; // Test Run TimeInt times = 50000; // number of cyc
All of the following code runs the environment: Windows 2003, Intel (R) Core (TM) 2 Duo CPU E8400 @ 3.00GHz 2.99GHZ,2.96GB MemoryAccording to some articles on the integrated Web, accurate timekeeping is mainly in the following ways1 calling the GetTickCount in the win API
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->[DllImport ("kernel32")]static extern uint GetTickCount ();The number of milliseconds
method.The Iii. examples(1)/** * First method: Set how long (in milliseconds) to perform a task*/ Public Static voidtimer1 () {Final StopWatch watch=NewStopWatch (); Watch.start (); Timer Timer=NewTimer (); /*void Java.util.Timer.schedule (timertask task, long delay)*/Timer.schedule (NewTimerTask () { Public voidrun () {watch.stop (); System. out. println ("-------Task Execution--------"); System. o
, each test code in the code needs to be encapsulated with the PER4J library. Let's first define the number of iterations
Copy Code code as follows:
private static final int outer_iteration=20;
private static final int inner_iteration=50000;
Next, we will use the above 4 methods to implement our test code.
Copy Code code as follows:
String addteststr = "";
String concatteststr = "";
StringBuffer CONCATTESTSB = null;
StringBuilder CONCATTESTSBU =
();Console. ForegroundColor = ConsoleColor. Red;Console. WriteLine ("filtered :");Console. ForegroundColor = color;Console. WriteLine (ws. Filter (str ));}Console. Read ();}
}
Output result:
In addition, a simple and practical code running time test class is provided to test the running time of a code segment.
Copy codeThe Code is as follows: using System;
Using System. Diagnostics;
Namespace WordFilter{/// /// Test code running time group class/// Public class OperationTimer: IDisposable{Pr
/200 ms to 1000 ms, respectively, because the main thread only waits for one of the semaphores to be sent, the result is output after 100 milliseconds (but note that the program is completed after 1 second, because these threads are foreground threads by default ). If we change waitany to waitall, the result is as follows:
In the previous article, we used manualresetevent to implement a signal for multiple people to respond. This time we impleme
The previous blog learned how to use multithreading in a simple way. In fact, the common multithreading is really simple, but a safe and efficient multithreading is not so simple. So many times improper use of multithreading will affect the performance of the program.Let's look at an example below:classProgram {Static intnum =1; Static voidMain (string[] args) {Stopwatch Stopwatch=NewStopwatch (); //Start T
Stopwatch timing.In fact it is the QueryPerformanceCounter, queryperformancefrequency two WINAPI package, if the hardware supports high precision, call QueryPerformanceCounter, If not supported, use Datetime.ticks to calculate.Usage:Stopwatch sw =newStopwatch();sw.Start();Thread.Sleep(2719);sw.Stop();Console.WriteLine(sw.ElapsedTicks / (decimal)Stopwatch.Frequency);6 with DateTime.Now.Ticks http://www.cnblogs.com/csharp4/archive/2010/07/24/1784094.ht
TSqlStatement ="Insert into BulkTestTable (Id, UserName, Pwd)" +"SELECT nc. Id, nc. UserName, nc. Pwd" +"FROM @ NewBulkTestTvp AS nc ";SqlCommand cmd = new SqlCommand (TSqlStatement, sqlConn );SqlParameter catParam = cmd. Parameters. AddWithValue ("@ NewBulkTestTvp", dt );CatParam. SqlDbType = SqlDbType. Structured;// The Name Of The Table value parameter is BulkUdt, which is included in the SQL statement used in the preceding test environment.CatParam. TypeName = "dbo. BulkUdt ";Try{SqlConn. O
. openwithoutpooling ();
The test results are as follows:
Without pooling, first connection elapsed 13 MSWithout pooling, average connection elapsed 5 MSWating for 10 sWithout pooling, first connection elapsed 6 MSWithout pooling, average connection elapsed 4 MSWating for 600 sWithout pooling, first connection elapsed 7 MSWithout pooling, average connection elapsed 4 MS
According to the test results, after the connection pool is closed, the average time consumed for each connection is
C # print the code running time,
You can use the following methods to accurately record the time consumed by code execution.System. Diagnostics. Stopwatch stopwatch = new Stopwatch ();Stopwatch. Start (); // starts to monitor the code running time// You code ....Stopwatch.
, average connection elapsed 4 ms
From this test, the average time to establish a physical connection is approximately 4 milliseconds per connection after closing the connection pool.
Next look at the default test code
Copy Code code as follows:
public static void Openwithpooling ()
{
String connectionString = "Data source=192.168.10.2;" Initial catalog=news; integrated security=true; ";
stopwatc
A proper understanding of this connection pooling mechanism helps us to write efficient database applications.
Many people think that the SqlConnection connection is not time-consuming, the reason is that the average time of the loop execution Sqlconnection.open is almost 0, but each time the first Open, time-consuming and often reach a few milliseconds to a few seconds, this is why?
First, let's take a look at the authoritative documentation on MSD
Inserting a single piece of data into SQL Server uses the INSERT statement, but if you want to bulk insert a bunch of data, looping through insert is inefficient and results in a system performance problem with SQL. The following are the two bulk data insertion methods supported by SQL Server: Bulk and table-valued parameters (table-valued Parameters).Run the following script to establish the test database and table-valued parameters. Copy the code code as follows:--create database Create databa
Code running time and code running
System. diagnostics. stopwatch stopwatch = new Stopwatch (); stopwatch. start (); // Start to monitor the code running time // code to be tested .... stopwatch. stop (); // Stop monitoring TimeSpan timespan =
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.