Skip to content

Instantly share code, notes, and snippets.

@wrosecrans
Created December 10, 2017 19:24
Show Gist options
  • Save wrosecrans/3cc8e9acf5b8201792ebbfa8554822e3 to your computer and use it in GitHub Desktop.
Save wrosecrans/3cc8e9acf5b8201792ebbfa8554822e3 to your computer and use it in GitHub Desktop.
$ python sql.py
setup: 0.0955448150635
queries: 2.39052200317
4183.18676286 queries/sec
----
import sqlite3
import time
conn = sqlite3.connect(':memory:')
c = conn.cursor()
def prep():
start = time.time()
c.execute('CREATE TABLE testing (name text, hitpoints real, id int, level int)')
for i in range(1,10000):
c.execute("INSERT INTO testing VALUES ('goblin', 47.5, " + `i` + ", 1) ")
for i in range(1,10000):
c.execute("INSERT INTO testing VALUES ('ogre', 87.2, " + `i+10000` + ", 1) ")
conn.commit()
end = time.time()
print "setup: ", end - start
def query():
start = time.time()
for i in range(1,10000):
a = c.execute ("Select * from testing where id=" + `i`)
end = time.time()
print "queries: ", end - start
print " ", 10000/(end - start), " queries/sec"
prep()
query()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment