The odbc package is often much faster than the existing RODBC and DBI compatible RODBCDBI packages. We’ll benchmark writing and reading data from the nycflights13 package using the three packages.
RODBC and RODBCDBI trip up on flights
’ tibble subclass,
so we’ll convert it to a data frame before passing to each package.
Also, the RODBCDBI package does not support writing timestamps, so we
remove that column as well.
Now, let’s configure three driver connections to a Microsoft SQL Server database, one for each package we’ll be benchmarking.
odbc <- dbConnect(odbc::odbc(), dsn = "MicrosoftSQLServer", uid = "SA", pwd = "BoopBop123!")
rodbc <- RODBC::odbcConnect(dsn = "MicrosoftSQLServer", uid = "SA", pwd = "BoopBop123!")
rodbcdbi <- dbConnect(RODBCDBI::ODBC(), dsn = "MicrosoftSQLServer", user = "SA", password = "BoopBop123!")
The above code requires a dsn
MicrosoftSQLServer
to have been previously configured; see
vignettes("setup")
to learn more.
We’ll first benchmark writing the flights dataset, which contains ~300,000 rows and 18 columns, to a database.
The code for odbc and RODBCDBI looks quite similar, as they both use the DBI front-end:
The timings for RODBC and RODBCDBI are quite similar, as they both utilize the RODBC back-end:
Again, the syntax for odbc and RODBCDBI is identical, while the timings for RODBCDBI and RODBC are quite similar.