Last active
January 18, 2024 10:34
-
-
Save jrosell/ac945095465a98a4d76cb8969ecdf748 to your computer and use it in GitHub Desktop.
Comparing the speed of multiple json R packages
This file contains 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
# R CMD BATCH --vanilla json-benchmark.R | |
output_dir <- setwd(here::here()) | |
grDevices::dev.set(1) | |
# simpleBenchmark | |
file <- system.file("jsonexamples", "twitter.json", package="RcppSimdJson") | |
jsontxt <- readLines(file) | |
res <- microbenchmark::microbenchmark( | |
jsonify = jsonify::validate_json(jsontxt), | |
jsonlite = jsonlite::validate(jsontxt), | |
simdjson = RcppSimdJson::validateJSON(file), | |
ndjson = ndjson::validate(file), | |
RJSONIO = RJSONIO::isValidJSON(file), | |
yyjsonr = yyjsonr::validate_json_file(file), | |
times = 100L | |
) | |
print(res, order="median") | |
p <- ggplot2::autoplot(res) + ggplot2::labs(title="Validate a JSON file (or string)") | |
ggplot2::ggsave(here::here(output_dir, "simpleBenchmark.png"), plot = p) | |
# simpleParseBenchmark | |
file <- system.file("jsonexamples", "twitter.json", package="RcppSimdJson") | |
json <- paste(readLines(file), collapse="") | |
res <- microbenchmark::microbenchmark(jsonify = jsonify::from_json(json), | |
jsonlite = jsonlite::fromJSON(json), | |
simdjson = RcppSimdJson::fparse(json), | |
ndjson = ndjson::flatten(json), | |
RJSONIO = RJSONIO::fromJSON(json), | |
yyjsonr = yyjsonr::read_json_str(json), | |
times = 100L) | |
print(res, order="median") | |
p <- ggplot2::autoplot(res) + ggplot2::labs(title="Parsing JSON string") | |
ggplot2::ggsave(here::here(output_dir, "simpleParseBenchmark.png"), plot = p) |
Author
jrosell
commented
Jan 18, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment