Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
benhaney committed Aug 16, 2022
1 parent 78d5bda commit 2c4a2d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add Jsonrs as a dependency in your `mix.exs` file.

```elixir
def deps do
[{:jsonrs, "~> 0.1"}]
[{:jsonrs, "~> 0.2"}]
end
```

Expand Down Expand Up @@ -37,7 +37,7 @@ If custom encoding defintions are not required, the first pass can be disabled e
## Performance

Jsonrs has different performance characteristics in different modes.
In the default 2-pass mode, Jsonrs is comparable feature-wise to Jason or Poison and should always be much faster (~5-10x) and consume less memory (~3-30x) than either of them.
In the default 2-pass mode, Jsonrs is comparable feature-wise to Jason or Poison and should always be much faster (~5-10x) and consume less memory (~3-30x) than either of them when working with any non-trivial JSON.
In lean mode, Jsonrs is comparable feature-wise to jiffy and should always be faster (~3x) and use less memory (~100x+) than it.

For example, here is a benchmark of Jsonrs's speed and memory consumption compared to other popular JSON libraries when encoding the 8MB [issue-90.json](https://github.com/devinus/poison/blob/a4208a6252f4e58fbcc8d9fd2f4f64c99e974cc8/bench/data/issue-90.json) from the Poison benchmark data.
Expand All @@ -60,8 +60,8 @@ It is easy to see that Jsonrs dramatically outperforms Poison and Jason, while J

### Basic usage
```elixir
iex> Jsonrs.encode!(%{"x" => [1,2], "y" => 0.5}) |> IO.puts()
{"x":[1,2],"y":0.5}
iex> Jsonrs.encode!(%{"x" => [1, 2], "y" => 0.5})
"{\"x\":[1,2],\"y\":0.5}"

iex> Jsonrs.decode!("{\"x\":[1,2],\"y\":0.5}")
%{"x" => [1, 2], "y" => 0.5}
Expand All @@ -75,6 +75,10 @@ iex> Jsonrs.encode!(%{"x" => false, "y" => []}, pretty: true) |> IO.puts()

### Defining a custom encoder

Implement `Jsonrs.Encoder` for your struct, with an `encode/1` function that returns any other type encodable by Jsonrs (it does not need to return a string).

For example:

```elixir
defimpl Jsonrs.Encoder, for: [MapSet, Range, Stream] do
def encode(struct), do: Enum.to_list(struct)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ defmodule Jsonrs.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:rustler, "~> 0.25.0"},
{:rustler_precompiled, "~> 0.5"},
{:rustler, "~> 0.25.0", optional: true},
{:ex_doc, "~> 0.27", only: :dev, runtime: false},
]
end
Expand Down

0 comments on commit 2c4a2d3

Please sign in to comment.