Last active
May 31, 2018 21:59
-
-
Save hadrianw/5151f926955a6bb1bfb54ac80db3532d to your computer and use it in GitHub Desktop.
Dumb benchmark for VPS performance measurment.
This file contains hidden or 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
#include <ftw.h> | |
#include <stdio.h> | |
#include <sqlite3.h> | |
#define INSERT_QUERY "INSERT INTO index VALUES (?, ?)", | |
static sqlite3 *db; | |
static sqlite3_stmt *insert_stmt; | |
static int step(const char *path, const struct stat *sb, int flag, struct FTW *ftwbuf) | |
{ | |
int fd; | |
char *fbuf; | |
if(flag != FTW_F) { | |
return 0; | |
} | |
sqlite3_bind_text(insert_stmt, 1, path, strlen(path), SQLITE_TRANSIENT); | |
fd = open(path, O_RDONLY); | |
fbuf = mmap(NULL, sb->st_size, PROT_READ, MAP_SHARED, fd, 0); | |
sqlite3_bind_text(insert_stmt, 2, fbuf, sb->st_size, SQLITE_TRANSIENT); | |
munmap(fbuf, sb->st_size); | |
// sqlite3_step | |
// sqlite3_reset | |
} | |
int main(int argc, char *argv[]) | |
{ | |
int rc = -1; | |
char *err = 0; | |
if(sqlite3_open(argv[1], &db)) { | |
fprintf(stderr, "sqlite3_open failed: %s\n", sqlite3_errmsg(db)); | |
goto out_close_db; | |
} | |
if(sqlite3_exec(db, "CREATE VIRTUAL TABLE index USING fts5(path, content)", NULL, NULL, &err) != SQLITE_OK) { | |
fprintf(stderr, "sqlite3_exec failed: %s\n", err); | |
sqlite3_free(err); | |
goto out_close_db; | |
} | |
if(sqlite3_prepare_v2(db, INSERT_QUERY, sizeof(INSERT_QUERY), &insert_stmt, NULL) != SQLITE_OK) { | |
fprintf(stderr, "sqlite3_prepare_v2 failed: %s\n", sqlite3_errmsg(db)); | |
goto out_close_db; | |
} | |
nftw(argv[2], step, 16, 0); | |
rc = 0; | |
out_close_db: | |
sqlite3_close(db); | |
return rc; | |
} |
This file contains hidden or 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
#include <stdio.h> | |
#include <sqlite3.h> | |
static int callback(void *NotUsed, int argc, char **argv, char **azColName) | |
{ | |
int i; | |
for(i = 0; i < argc; i++){ | |
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); | |
} | |
puts(""); | |
return 0; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
sqlite3 *db; | |
char *err = 0; | |
int rc = -1; | |
if(sqlite3_open(argv[1], &db)) { | |
fprintf(stderr, "sqlite3_open failed: %s\n", sqlite3_errmsg(db)); | |
goto out_close_db; | |
} | |
if(sqlite3_exec(db, argv[2], callback, 0, &err) != SQLITE_OK) { | |
fprintf(stderr, "sqlite3_exec failed: %s\n", err); | |
sqlite3_free(zErrMsg); | |
goto out_close_db; | |
} | |
rc = 0; | |
out_close_db: | |
sqlite3_close(db); | |
return rc; | |
} |
This file contains hidden or 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
#!/bin/bash | |
set -e | |
set -x | |
JOBS="$1" | |
time git clone --depth 1 --branch v4.10 "git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git" | |
(cd linux | |
make defconfig | |
time make -j"$JOBS" | |
) | |
time wget "https://www.sqlite.org/2017/sqlite-amalgamation-3210000.zip" | |
time unzip sqlite-*.zip | |
time gcc -O2 index.c sqlite/sqlite3.c -Isqlite -DSQLITE_ENABLE_FTS5 -o index | |
time ./index database.sqlite linux | |
time gcc -O2 search.c sqlite/sqlite3.c -Isqlite -DSQLITE_ENABLE_FTS5 -o search | |
time ./search database.sqlite frobnicate | |
time ./search database.sqlite static |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment