Last active
April 11, 2022 22:47
-
-
Save danielrmeyer/bfa415256502471d1512f2155e76adc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
from itertools import cycle, product | |
DB_FILE = "data.sqlite3" | |
num_rows = 100000000 | |
elements = cycle(product(["name1", "name2", "name3"], [1,2,3])) | |
conn = sqlite3.connect(DB_FILE) | |
curs = conn.cursor() | |
curs.execute("CREATE TABLE test (name string, val integer);") | |
curs.executemany("INSERT INTO test (name, val) VALUES (?, ?)", | |
[next(elements) for row in range(num_rows)]) | |
conn.commit() | |
curs.execute("select count(*) from test") |
Yep, your right. Data is computed twice. fixing...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I see a ref "data" is assigned a list of elements from a cycle but it is never used --- However --- the code that generates "data" is run again on lines 14 and 15
so maybe:
-- 14; --15
++14: curs.executemany("INSERT INTO test (name, val) VALUES (?, ?)", data)
Or did I miss something?