Advertisement
Guest User

Untitled

a guest
May 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. defmodule Builder.LinkBench do
  2. alias JaSerializer.Builder.Link
  3. use Benchfella
  4.  
  5. @template %Link.Compiled{template: "/widget/~s", meths: [:id]}
  6.  
  7. bench "with a binary",
  8. [context: context()],
  9. do: Link.build(context, :related, "/widget/:id")
  10.  
  11. bench "with an atom",
  12. [context: context()],
  13. do: Link.build(context, :related, :id_href)
  14.  
  15. bench "with a compiled template",
  16. [context: context()],
  17. do: Link.build(context, :related, @template)
  18.  
  19. defmodule Serializer do
  20. def id(%{id: id}, _), do: id
  21. def id_href(%{id: id}, _), do: "/widget/#{id}"
  22. end
  23.  
  24. defp context, do: %{serializer: Serializer, data: %{id: 1}, conn: nil}
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement