Skip to content

Instantly share code, notes, and snippets.

@danielrmeyer
Last active April 11, 2022 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save danielrmeyer/bfa415256502471d1512f2155e76adc2 to your computer and use it in GitHub Desktop.
Save danielrmeyer/bfa415256502471d1512f2155e76adc2 to your computer and use it in GitHub Desktop.
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")
@Sonophoto
Copy link

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?

@danielrmeyer
Copy link
Author

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