File tree Expand file tree Collapse file tree 6 files changed +12
-29
lines changed
frameworks/Elixir/plug/lib/framework_benchmarks Expand file tree Collapse file tree 6 files changed +12
-29
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,10 @@ defmodule FrameworkBenchmarks.Handlers.CachedWorld do
1111 :rand . uniform ( 10_000 )
1212 end )
1313
14- { :ok , json } =
14+ json =
1515 ids
1616 |> Enum . map ( & FrameworkBenchmarks.CachedWorld . get / 1 )
17- |> Jason . encode ( )
17+ |> Jason . encode_to_iodata! ( )
1818
1919 conn
2020 |> Plug.Conn . put_resp_content_type ( "application/json" )
Original file line number Diff line number Diff line change @@ -5,11 +5,9 @@ defmodule FrameworkBenchmarks.Handlers.DB do
55 def handle ( conn ) do
66 id = :rand . uniform ( 10_000 )
77
8- { :ok , json } =
8+ json =
99 FrameworkBenchmarks.Repo . get ( FrameworkBenchmarks.Models.World , id )
10- |> Map . from_struct ( )
11- |> Map . drop ( [ :__meta__ ] )
12- |> Jason . encode ( )
10+ |> Jason . encode_to_iodata! ( )
1311
1412 conn
1513 |> Plug.Conn . put_resp_content_type ( "application/json" )
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ defmodule FrameworkBenchmarks.Handlers.JSON do
33 This is the handle for the /json route
44 """
55 def handle ( conn ) do
6- { :ok , json } = Jason . encode ( % { message: "Hello, World!" } )
6+ json = Jason . encode_to_iodata! ( % { message: "Hello, World!" } )
77
88 conn
99 |> Plug.Conn . put_resp_content_type ( "application/json" )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ defmodule FrameworkBenchmarks.Handlers.Query do
55 def handle ( conn ) do
66 number_of_queries = FrameworkBenchmarks.Handlers.Helpers . parse_queries ( conn , "queries" )
77
8- records =
8+ json =
99 1 .. number_of_queries
1010 |> Enum . map ( fn _ ->
1111 :rand . uniform ( 10_000 )
@@ -15,16 +15,8 @@ defmodule FrameworkBenchmarks.Handlers.Query do
1515 FrameworkBenchmarks.Repo . get ( FrameworkBenchmarks.Models.World , & 1 )
1616 end )
1717 )
18- |> Enum . map ( & Task . await ( & 1 ) )
19-
20- { :ok , json } =
21- records
22- |> Enum . map ( fn record ->
23- record
24- |> Map . from_struct ( )
25- |> Map . drop ( [ :__meta__ ] )
26- end )
27- |> Jason . encode ( )
18+ |> Enum . map ( & Task . await ( & 1 , :infinity ) )
19+ |> Jason . encode_to_iodata! ( )
2820
2921 conn
3022 |> Plug.Conn . put_resp_content_type ( "application/json" )
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ defmodule FrameworkBenchmarks.Handlers.Update do
2222 :rand . uniform ( 10_000 )
2323 end )
2424
25- records =
25+ json =
2626 ids
2727 |> Enum . map (
2828 & Task . async ( fn ->
@@ -38,16 +38,8 @@ defmodule FrameworkBenchmarks.Handlers.Update do
3838 |> FrameworkBenchmarks.Repo . update! ( )
3939 end )
4040 )
41- |> Enum . map ( & Task . await ( & 1 ) )
42-
43- { :ok , json } =
44- records
45- |> Enum . map ( fn record ->
46- record
47- |> Map . from_struct ( )
48- |> Map . drop ( [ :__meta__ ] )
49- end )
50- |> Jason . encode ( )
41+ |> Enum . map ( & Task . await ( & 1 , :infinity ) )
42+ |> Jason . encode_to_iodata! ( )
5143
5244 conn
5345 |> Plug.Conn . put_resp_content_type ( "application/json" )
Original file line number Diff line number Diff line change 11defmodule FrameworkBenchmarks.Models.World do
22 use Ecto.Schema
33
4+ @ derive { Jason.Encoder , only: [ :id , :randomnumber ] }
45 schema "world" do
56 field ( :randomnumber , :integer )
67 end
You can’t perform that action at this time.
0 commit comments