Skip to content

Instantly share code, notes, and snippets.

@timrprobocom
Created March 10, 2022 05:27
Show Gist options
  • Save timrprobocom/5a42ad929d42d28cb56cdacb23c29db2 to your computer and use it in GitHub Desktop.
Save timrprobocom/5a42ad929d42d28cb56cdacb23c29db2 to your computer and use it in GitHub Desktop.
Sample Database Benchmark
# OK, I ran the following Python to create the database:
import sqlite3
import random
import os
os.remove( 'test.db' )
db = sqlite3.connect( "test.db" )
cursor = db.cursor()
cursor.execute( """\
CREATE TABLE mark (
property1 VARCHAR(2),
property2 VARCHAR(2),
property3 VARCHAR(2),
property4 INTEGER,
property5 INTEGER,
property6 SMALLINT
);""")
p1 = "ABCDEFGH"
for i in (1,2,3,4,5,6):
cursor.execute( f"CREATE INDEX prop{i} on mark (property{i});" )
for i in range(10000):
if i % 10 == 0:
print(i,end='\r')
s = []
for _ in range(1000):
s.append([
random.choice( p1 ),
random.choice( p1 ),
random.choice( p1 ),
str(random.randrange(0,10) ),
str(random.randrange(0,10) ),
str(random.randrange(0,1) )
] )
cursor.executemany( "INSERT INTO mark VALUES (?,?,?,?,?,?);", s )
db.commit()
## This created an 850MG database file. I then ran the query in your example:
timr@tims-gram:~/src$ cat test.sql
SELECT * FROM mark
WHERE property1='A'
AND property2 IN ('D','F')
AND property4=0
AND property5 BETWEEN 3 AND 6
AND property6 = 1;
timr@tims-gram:~/src$ time sqlite3 test.db < test.sql
real 0m0.004s
user 0m0.003s
sys 0m0.001s
timr@tims-gram:~/src$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment