(To be verified) correct an incorrect "batch insert data in typed dataset" in the instructor's free video

Source: Internet
Author: User

In the "batch operation of Typed Dataset" section 30th, the instructor suggested to manually open the database connection and then Perform Batch insertion when inserting data in batches. The effect is as follows: manual connection insertion saves as much time as 20 times (45 seconds and 2 seconds) than manual connection insertion)

(Instructor video code)

I have read some questions, because we know that it takes a lot of time to run the program first, for example, when we run large software such as Photoshop, the first running is much faster than the first running.

This is because the data has been loaded into the memory for the first time. After it is closed, it is called directly from the memory (just loaded, not yet released. Of course it will be much faster.

So I guess that the instructor added "manually open the connection" for 2nd times.Code"ProgramThe light of a program that has been running for 1st times, the light of memory, the so-called waves in the Yangtze River, the waves in front of the beach, and the waves in the back of the beach.

So I tested three cases and run them n times. (The database is cleared each time to prevent the loading of data files from being too large and slow.) The result is as follows:

1. Insert 3000 pieces of data. The two types of code run n times in succession (to prevent the exposure of memory light). The time difference is not large. One Code takes 2 seconds and the other one takes 1 second;

2. Insert 10000 data records. The result is the same as the preceding one. It takes 2 seconds and 1 second;

It seems that the data volume is small, and the number is increased to 50000:

3. Insert 50000 pieces of data. The two types of code run n times successively. It takes 30 seconds to manually open the connection, and 37 seconds to manually open the connection.It seems that the difference is not as obvious as the teacher said.

Why? If you have any questions, please feel free to ask.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.