C # Run Time of the test code,
You can use the following methods to accurately record the time consumed by code execution.
System. diagnostics. stopwatch stopwatch = new Stopwatch (); stopwatch. start (); // Start to monitor the code running time // you code .... stopwatch
4 MS
According to the test results, after the connection pool is closed, the average time consumed for each connection is about 4 milliseconds, which is the average time consumed for establishing a physical connection.
Next, let's look at the default test code.
Copy codeThe Code is as follows: public static void OpenWithPooling ()
{
String connectionString = "Data Source = 192.168.10.2; Initial Catalog = News; Integrated Security = True ;";
Correct understanding of this connection pool mechanism helps us to write efficient database applications.
Many people think that the SqlConnection connection is not time-consuming, because SqlConnection is executed cyclically. the average Open time is almost 0, but the time consumed for the first open usually ranges from several milliseconds to several seconds. Why?
First, let's take a look at what is said in the authoritative document on MSDN.
Conne
= memcachedmain.memcachedinitialize (); Memcachedclient client = Memcachedmain.getmemcachedinst Ance (); 18//Check whether the memcached cache the user information if (client. Keyexists ("user") client. Keyexists ("Pass")) (user. User = = Client. Get ("User"). ToString () user. Pass = = Client. Get ("Pass"). ToString ()) ("Login successful!") {Debug.WriteLine User information has been obtained from the memcached! "); 24 }25 ismemcachedfinished = true;26}27 memcachedwatch.stop (
. WriteLine ("Waiting for 600 s ");System. Threading. Thread. Sleep (600*1000 );Test. SqlConnectionTest. 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
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 MSAccording to the test results, after the connection pool is closed, the average time consumed for each connection is about 4 milliseconds, which is
1 ', 160
UNION all
SELECT NEWID (), ' Cattle 2 ', 180
UNION All
...
Mode four: Splicing SQL
INSERT into Product (id,name,price) VALUES
(NEWID (), ' pen 1 ', 160)
, (NEWID (), ' Pen 2 ',) ...
There are four different ways to implement bulk operations in C # by Ado.net.
Way one: inserting
#region Way One static void Insertone () {Console.WriteLine ("implemented in a single insert Way");
stopwatch SW = new
Spinach Platform Construction test the first way: Enterprise e: 217 1793 408System.Diagnostics.Stopwatch Stopwatch = new Stopwatch ();Stopwatch. Start (); Start monitoring code run timeCode that needs to be tested ....Stopwatch. Stop (); Stop monitoringTimeSpan timespan = stopwatch
measured in milliseconds, so it can only be accurate to 1ms. But in fact very unstable, thread.sleep (1) will be in 1ms and 2ms two of the state between the beat, that is, may produce +1ms many errors.
It was found that there was no task load (pure loop call Sleep (1)), the length of blocking was stable at 2ms, and at least 1ms was blocked when there was a task load. This is different from the other two ways of blocking, as detailed in the following
SYN5301 type Time Verification DeviceFixture overviewOur fixture can be placed horizontally measured stopwatch, but also vertical measurement of the stopwatch, and other manufacturers of fixtures can only be measured horizontally, if you want to vertical measurement to rely on the wall or other objects to test, so that the detected data will have a certain deviation, and their fixture rough, 2, other manufa
Microsoft introduced dynamic attribute dynamic in 4.0, so we can implement some reflection functions and greatly improve the performance.
The following is an example of reflection without using dynamic.
Class Program{ Static Void Main ( String [] ARGs){Dynamicsample = New Dynamicsample (); // How to Get dynamicsample through reflection VaR Add = dynamicsample. GetType (). getmethod (" Add " );Stopwatch watch = New
SetTimeout
Describe
SetTimeout (CODE,MILLISEC)
The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.
Note: During the call process, you can use Cleartimeout (id_of_settimeout) to terminate
Parameters
Description
Code
Required, the JavaScript code string to be executed after the function to be invoked.
Millisec
Required, the num
million data to test. The specific tests are as follows:When you click the total number of data, the total number of records of the database Operation log table, click Load Data, the 1.1 million data page, 10 per page, take the third page of 10 data, the point of emptying data, the data loaded in the table is emptied: The total number of entries is as follows: First run, click Load Data, A total of 9100 milliseconds: then click to erase the data, cli
In the writing H5 game often need to use the Timed Refresh page to achieve the animation effect, more commonly known as settimeout () and setinterval (), but everyone on the use of setinterval and settimeout understand, The following through this article for everyone to explain the use of JS in SetInterval and settimeout, need to refer to the friendSetTimeoutDescribeSetTimeout (CODE,MILLISEC)The SetTimeout () method is used to call a function or evaluate an expression after a specified number of
Example one:
View Demo Download source code
The settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds, while SetInterval () invokes the function or expression at the specified number of milliseconds, until clearinterval clears it. That is, settimeout () is executed only once, and setinterval () can be executed multiple times. The parameters for
understand that, just as if 0.1 million of the first people crossed the bridge, the time would be different if 0.1 million people passed the bridge or zhuqiao.
The above is the time for parallel processing of 1000 connections, 3427 milliseconds. For Single-thread serial, let's take a look at its processing time.
Code
[TestMethod] public void SignalRead() { Stopwatch sw = ne
= "User Id=scott; Password=tiger;data source= ";
OracleConnection conn = new OracleConnection (CONNECTSTR);
OracleCommand command = new OracleCommand ();
Command. Connection = conn;
Conn. Open ();
stopwatch SW = new Stopwatch ();
Sw. Start ();
By looping through a lot of data, this method is obviously a meat mat
for (int i = 0; i
{
String sql = "INSERT INTO dept values (" + i.tostring ()
+ ","
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.