Skip to content

Commit

Permalink
measure performance of json diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Nelson committed Apr 6, 2024
1 parent 297e893 commit b21a5cb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/json_differ_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule LiveState.Test.JsonDifferTest do
use ExUnit.Case

test "performance" do
map = Enum.reduce(1..1_00000, %{}, fn i, map ->
Map.put(map, "foo_#{i}", "bar")
end)
map2 = map |> Map.put("foo_997", "bing")
{usec, _} = :timer.tc(fn ->
json1 = Jason.encode!(map)
json2 = Jason.encode!(map2)

LiveState.JSONDiffer.build_patch_message(json1, json2, 2)
end)
IO.inspect(usec / 1_000, label: "rust json diffing")
{elixir_usec, _} = :timer.tc(&JSONDiff.diff/2, [map, map2])
IO.inspect(elixir_usec / 1_000, label: "elixir json diffing")
end
end

0 comments on commit b21a5cb

Please sign in to comment.