Created
October 17, 2019 22:32
-
-
Save Mytherin/25c79b75446314659df42995c43158e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import os | |
import time | |
# showcase of a bug in the python version of sqlite3 | |
# starting an insert with a comment will result in much slower performance and rowcount not being set properly | |
def test(with_comment): | |
os.system('rm -f test.db') | |
con = sqlite3.connect('test.db') | |
c = con.cursor() | |
start = time.time() | |
c.execute('CREATE TABLE integers(i INTEGER)') | |
if with_comment: | |
insert_query = """ | |
-- insert many values into the db | |
INSERT INTO integers VALUES ($1) | |
""" | |
else: | |
insert_query = 'INSERT INTO integers VALUES ($1)' | |
c.executemany(insert_query, [(x,) for x in range(0, 10000)]) | |
print(c.rowcount) | |
con.commit() | |
end = time.time() | |
return str(end - start) | |
# around ~0.01 seconds | |
print('normal executemany time: ' + test(False) + "s") | |
# around ~10 seconds | |
print('comment executemany time: ' + test(True) + "s") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment