Skip to content

Commit

Permalink
update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbutuseless committed Jan 13, 2024
1 parent c944375 commit 268bc2c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 110 deletions.
111 changes: 2 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,114 +96,6 @@ read_json_str(str)
#> 3 4.7 3.2 1.3 0.2 setosa
```

# Parsing differences compared to `{jsonlite}`

## 3-d arrays are parsed as multiple 2-d matrices and combined

In `{yyjsonr}` the order in which elements in an array are serialized to
JSON correspond to an array of row-major matrices in human-readable
order.

`{jsonlite}` does things differently.

The array formats are internally consistent within each package, but not
cross-compatible between them i.e. you cannot serialize an array in
`{yyjsonr}` and re-create it exactly using `{jsonlite}`.

``` r
# A simple 3D array
mat <- array(1:12, dim = c(2,3,2))
mat
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 7 9 11
#> [2,] 8 10 12
```

``` r
# jsonlite's serialization of matrices is internally consistent and re-parses
# to the initial matrix.
str <- jsonlite::toJSON(mat, pretty = TRUE)
cat(str)
#> [
#> [
#> [1, 7],
#> [3, 9],
#> [5, 11]
#> ],
#> [
#> [2, 8],
#> [4, 10],
#> [6, 12]
#> ]
#> ]
jsonlite::fromJSON(str)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 7 9 11
#> [2,] 8 10 12
```

``` r
# yyjsonr's serialization of matrices is internally consistent and re-parses
# to the initial matrix.
# But note that it is *different* to what jsonlite does.
str <- yyjsonr::write_json_str(mat, pretty = TRUE)
cat(str)
#> [
#> [
#> [
#> 1,
#> 3,
#> 5
#> ],
#> [
#> 2,
#> 4,
#> 6
#> ]
#> ],
#> [
#> [
#> 7,
#> 9,
#> 11
#> ],
#> [
#> 8,
#> 10,
#> 12
#> ]
#> ]
#> ]
yyjsonr::read_json_str(str)
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 7 9 11
#> [2,] 8 10 12
```

## Future

- Re-introduce NDJSON support
Expand All @@ -218,7 +110,8 @@ yyjsonr::read_json_str(str)
## Limitations

- Some datatypes not currently supported. Please file an issue on GitHub
if these types are critical for yoy:
if these types are critical for you. Providing test cases also
appreciated!:
- Complex numbers
- POSIXlt
- Matrices of POSIXct / Date
Expand Down
2 changes: 1 addition & 1 deletion man/benchmark/benchmarks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ ggplot(plot_df) +
facet_wrap(~benchmark, scales = 'free_y', ncol = 3) +
theme_bw() +
theme(legend.position = 'none') +
scale_fill_manual(values = c(rep(grey(0.5), 3), 'dodgerblue3')) +
scale_fill_manual(values = c(rep(grey(0.5), 2), 'dodgerblue3')) +
geom_hline(yintercept = 1, color = 'red', alpha = 0.5, linetype = 2) +
labs(
x = NULL,
Expand Down
Binary file modified man/figures/benchmark-summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 268bc2c

Please sign in to comment.