Skip to content

Instantly share code, notes, and snippets.

@omaraboumrad
Created March 19, 2013 11:49
Show Gist options
  • Save omaraboumrad/5195472 to your computer and use it in GitHub Desktop.
Save omaraboumrad/5195472 to your computer and use it in GitHub Desktop.
sqlite table creation speed.
# Slow: python test.py
# Fast: python test.py -p /path/to/ramdisk
import os
import sqlite3
# Helper
from optparse import OptionParser
options = OptionParser()
options.add_option("-p", "--prefix", dest="prefix", default='')
(options, args) = options.parse_args()
# If a prefix is provided, use it otherwise use current directory
conn = sqlite3.connect(os.path.join(options.prefix, 'example.db'))
c = conn.cursor()
# You can even use a transaction if you want (Not used here)
for i in xrange(100):
print 'Creating table: stocks{0}'.format(i)
c.execute('''CREATE TABLE stocks{0} (date text, trans text, symbol, text, qty real, price real)'''.format(i))
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment