across the web I can read that I should use data.table and fread to load my data.
But when I run a benchmark, then I get the following results
Unit: milliseconds
expr min lq mean median uq max neval
test1 1.229782 1.280000 1.382249 1.366277 1.460483 1.580176 10
test3 1.294726 1.355139 1.765871 1.391576 1.542041 4.770357 10
test2 23.115503 23.345451 42.307979 25.492186 57.772522 125.941734 10
where the code can be seen below.
loadpath <- readRDS("paths.rds")
microbenchmark(
test1 = read.csv(paste0(loadpath,"data.csv"),header=TRUE,sep=";", stringsAsFactors = FALSE,colClasses = "character"),
test2 = data.table::fread(paste0(loadpath,"data.csv"), sep=";"),
test3 = read.csv(paste0(loadpath,"data.csv")),
times = 10
) %>%
print(order = "min")
I understand that fread()
should be faster than read.csv()
because it tries to first read rows into memory as character and then tries to convert them into integer and factor as data types. On the other hand, fread()
simply reads everything as character.
If this is true, shouldn't test2
be faster than test3
?
Can someone explain me, why I do not archieve a speed-up or atleast the same speed with test2
as test1
? :)