mkearney / readthat Goto Github PK
View Code? Open in Web Editor NEWRead Text Data
License: Other
Read Text Data
License: Other
readr::read_lines()
is not equivalent to readthat::read()
, or readLines()
, the former returns a single vector with the full file contents whereas the latter are returning a vector of lines. You should benchmark against readr::read_file()
and readChar()
.
bench::mark()
tried to warn you of this, but you seem to have overridden this by using check = FALSE
.
Benchmarking with the equivalent functions and larger inputs gives you different results.
The overhead in readr comes from the R code prior to dropping down to C++, once you use a large enough input all of the methods end up being largely equivalent.
library(readthat)
urls <- c(
"https://mikewk.com",
"https://cnn.com",
"https://www.cnn.com/us"
)
bench::press(
n = c(1, 10, 100, 1000),
{
writeLines(rep(read(urls[1]), n), x <- tempfile())
bench::mark(
readr = readr::read_file(x),
readthat = read(x),
readChar = readChar(x, file.size(x), useBytes = TRUE)
)
}
)
#> Running with:
#> n
#> 1 1
#> 2 10
#> 3 100
#> 4 1000
#> # A tibble: 12 x 7
#> expression n min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <dbl> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 readr 1 249.87µs 269.23µs 3502. 1.32MB 4.06
#> 2 readthat 1 93.52µs 99.94µs 9452. 21KB 2.01
#> 3 readChar 1 66.89µs 75.33µs 12114. 20.34KB 4.09
#> 4 readr 10 435.9µs 466µs 2083. 126.55KB 2.02
#> 5 readthat 10 290.4µs 310.59µs 3079. 126.55KB 2.02
#> 6 readChar 10 255.39µs 311.93µs 3091. 124.06KB 6.55
#> 7 readr 100 2.31ms 2.44ms 404. 1.21MB 0
#> 8 readthat 100 2.29ms 2.46ms 399. 1.21MB 0
#> 9 readChar 100 1.99ms 2.6ms 393. 1.21MB 10.9
#> 10 readr 1000 23.57ms 24.3ms 40.8 12.11MB 0
#> 11 readthat 1000 25.97ms 27.06ms 37.1 12.11MB 0
#> 12 readChar 1000 21.97ms 22.88ms 43.8 12.11MB 25.6
Created on 2019-10-22 by the reprex package (v0.3.0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.