Skip to content

Instantly share code, notes, and snippets.

@blongworth
Created November 28, 2021 13:11
Show Gist options
  • Save blongworth/e8b3316fd42989be4793c533df5a81ba to your computer and use it in GitHub Desktop.
Save blongworth/e8b3316fd42989be4793c533df5a81ba to your computer and use it in GitHub Desktop.
Test speed of dbAppendTable
# Testing methods for inserting data from a file into a SQLite DB
library(DBI)
db<-dbConnect(RSQLite::SQLite(),dbname=":memory")
dbExecute(db,
"CREATE TABLE TABLE1(
MARKS INTEGER,
ROLLNUM INTEGER,
NAME TEXT
)"
)
df <- data.frame(MARKS = sample(1:100, 100000, replace = TRUE),
ROLLNUM = sample(1:100, 100000, replace = TRUE),
NAME = stringi::stri_rand_strings(100000, 10))
write.table(df, file.path(tempdir(), "dbtest.txt"), sep = "|")
bench::mark({
tb <- read.delim(file.path(tempdir(), "dbtest.txt"), sep = "|")
dbAppendTable(db, "TABLE1", tb)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment