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) |
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> # R CMD BATCH --vanilla json-benchmark.R
> output_dir <- setwd(here::here())
> grDevices::dev.set(1)
null device
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
+ )
Registered S3 method overwritten by 'jsonify':
method from
print.json jsonlite
> print(res, order="median")
Unit: microseconds
expr min lq mean median uq max
yyjsonr 448.825 561.1735 716.8716 667.8380 759.3715 3354.802
simdjson 445.594 587.3300 836.7611 774.2215 918.8510 6301.559
jsonify 3702.561 4241.7280 5074.4840 4676.2690 5337.2575 11296.512
jsonlite 6819.402 7553.0285 9101.7492 8517.3535 9302.2035 23988.623
RJSONIO 13915.231 15173.1345 17323.3559 17300.2420 17937.9050 31750.315
ndjson 132535.668 147297.1685 167922.0323 158292.6110 166997.3670 290134.665
neval cld
100 b
100 b
100 ab
100 a
100 d
100 c
> p <- ggplot2::autoplot(res) + ggplot2::labs(title="Validate a JSON file (or string)")
> ggplot2::ggsave(here::here(output_dir, "simpleBenchmark.png"), plot = p)
Saving 7 x 7 in image
>
>
> # 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")
Unit: milliseconds
expr min lq mean median uq max neval
yyjsonr 2.752954 2.957143 3.651587 3.194147 3.721455 20.270499 100
simdjson 3.633885 4.161745 4.978973 4.577095 5.280067 9.053087 100
jsonify 14.386760 15.592567 19.508955 17.084299 22.976594 31.150945 100
RJSONIO 18.121915 20.266469 24.436466 22.608387 26.761010 42.650437 100
ndjson 45.317341 49.499249 58.937256 53.639392 60.690322 129.146639 100
jsonlite 46.134665 53.321075 61.141952 56.703371 62.757238 107.240635 100
cld
c
c
a
d
b
b
> p <- ggplot2::autoplot(res) + ggplot2::labs(title="Parsing JSON string")
> ggplot2::ggsave(here::here(output_dir, "simpleParseBenchmark.png"), plot = p)
Saving 7 x 7 in image
>
> proc.time()
user system elapsed
42.560 1.587 42.544
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here my results. I use Ubuntu 22.04.