Skip to content

Instantly share code, notes, and snippets.

@andy-wm-arthur
Created June 1, 2022 22:59
Show Gist options
  • Save andy-wm-arthur/1169c05a17be79e96df5fea2ffc80509 to your computer and use it in GitHub Desktop.
Save andy-wm-arthur/1169c05a17be79e96df5fea2ffc80509 to your computer and use it in GitHub Desktop.
Dolt Diff vs. Sqlite Diff Benchmark
#!/bin/bash
SCALE=100000
if [ ! -z "$1" ]; then
SCALE="$1"
fi
# generate source data
cat << DOC > psv_gen.py
with open('$SCALE.psv', 'w+') as f:
f.write('pk|c0|c1|c2\n')
for i in range ($SCALE):
s = '{}|{}|{}|{}\n'.format(i,i,i,i)
f.write(s)
DOC
python3 psv_gen.py
rm psv_gen.py
# use source data to create and benchmark a dolt database
rm -rf .dolt
DOLT_DEFAULT_BIN_FORMAT="__DOLT_1__" dolt init > /dev/null
dolt table import -pk=pk -c difftbl "$SCALE.psv" > /dev/null
dolt add -A && dolt commit -m "created difftbl" > /dev/null
dolt sql -q "delete from difftbl where pk = 1234;" > /dev/null
dolt commit -am "create point diff" > /dev/null
echo "benchmarking dolt database (SCALE=$SCALE)"
time dolt sql -q "SELECT count(*) FROM dolt_commit_diff_difftbl WHERE to_commit=HASHOF('HEAD') AND from_commit=HASHOF('HEAD^')" > /dev/null
echo ""
# use source data to create and benchmark a sqlite database
rm diff.db diff2.db
sqlite3 diff.db "create table difftbl (pk int primary key, c0 int, c1 int, c2 int)"
sqlite3 diff.db ".import $SCALE.psv difftbl"
cp diff.db diff2.db
sqlite3 diff2.db "delete from difftbl where pk = 1234"
echo "benchmarking sqlite3 database (SCALE=$SCALE)"
time sqldiff diff.db diff2.db > /dev/null
echo ""
# cleanup
rm psv_gen.py
rm "$SCALE.psv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment