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.