Today, a friend of the test SQLite, and then came to the conclusion that: SQLite efficiency is too low, batch insert 1000 records, incredibly time-consuming 2 minutes!
Here is the test code he sent me. I'm dizzy ~~~~~~.
Using System.Data;
Using System.Data.Common;
Using System.Data.SQLite;
Creating a Database File
File.delete ("test1.db3");
Sqliteconnection.createfile ("test1.db3");
DbProviderFactory factory = sqlitefactory.instance;
using (DbConnection conn = factory. CreateConnection ())
{
Connecting to a database
Conn. ConnectionString = "Data source=test1.db3";
Conn. Open ();
Start the timer.
Stopwatch watch = new stopwatch ();
Watch. Start ();
Insert 1000 consecutive records
for (int i = 0; i < 1000; i++)
{
Cmd.commandtext = "INSERT INTO [test1] ([s]) VALUES (?)";
Cmd. Parameters[0]. Value = i.ToString ();
It takes 0.2 seconds to execute. Is that a little too big a difference?
Why is it that there is so much difference between simply enabling a transaction? Quite simply, SQLite the default to start a transaction for each operation, then the original code 1000 inserts to open at least 1000 transactions, "Transaction Open + SQL execution + transaction shutdown" Naturally consumes a lot of time, which is also the reason why so fast after the start of the transaction. In fact, this is the basic knowledge of database operations, we should remember that bad code efficiency is not the 1:30 point.
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.