Created
March 19, 2013 11:49
-
-
Save omaraboumrad/5195472 to your computer and use it in GitHub Desktop.
sqlite table creation speed.
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
# 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