| Message |
As luck has it, I have been reading the Sqlite3 documentation about speed tests.
I can confirm that a test script for me did indeed take about 4 seconds to insert 300 records.
But there is a simple solution - transactions. If you wrap the whole set of inserts into a transaction it is much faster. For example:
start = os.time ()
assert (con:execute ("BEGIN TRANSACTION"))
for i = 1, 10000 do
assert (con:execute(string.format([[
INSERT INTO players
VALUES ('player %i', 'class %i'); ]], i, i)
))
end
assert (con:execute ("COMMIT"))
fin = os.time ()
print ("time = ", os.difftime (fin , start)) --> 1
In my test the insert of 300 records seemed instantaneous, and in the script above it only took 1 second to insert 10,000 records.
So, transactions are your friend. :-) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|