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
11
11
:rand . uniform ( 10_000 )
12
12
end )
13
13
14
- { :ok , json } =
14
+ json =
15
15
ids
16
16
|> Enum . map ( & FrameworkBenchmarks.CachedWorld . get / 1 )
17
- |> Jason . encode ( )
17
+ |> Jason . encode_to_iodata! ( )
18
18
19
19
conn
20
20
|> 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
5
5
def handle ( conn ) do
6
6
id = :rand . uniform ( 10_000 )
7
7
8
- { :ok , json } =
8
+ json =
9
9
FrameworkBenchmarks.Repo . get ( FrameworkBenchmarks.Models.World , id )
10
- |> Map . from_struct ( )
11
- |> Map . drop ( [ :__meta__ ] )
12
- |> Jason . encode ( )
10
+ |> Jason . encode_to_iodata! ( )
13
11
14
12
conn
15
13
|> 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
3
3
This is the handle for the /json route
4
4
"""
5
5
def handle ( conn ) do
6
- { :ok , json } = Jason . encode ( % { message: "Hello, World!" } )
6
+ json = Jason . encode_to_iodata! ( % { message: "Hello, World!" } )
7
7
8
8
conn
9
9
|> 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
5
5
def handle ( conn ) do
6
6
number_of_queries = FrameworkBenchmarks.Handlers.Helpers . parse_queries ( conn , "queries" )
7
7
8
- records =
8
+ json =
9
9
1 .. number_of_queries
10
10
|> Enum . map ( fn _ ->
11
11
:rand . uniform ( 10_000 )
@@ -15,16 +15,8 @@ defmodule FrameworkBenchmarks.Handlers.Query do
15
15
FrameworkBenchmarks.Repo . get ( FrameworkBenchmarks.Models.World , & 1 )
16
16
end )
17
17
)
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! ( )
28
20
29
21
conn
30
22
|> 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
22
22
:rand . uniform ( 10_000 )
23
23
end )
24
24
25
- records =
25
+ json =
26
26
ids
27
27
|> Enum . map (
28
28
& Task . async ( fn ->
@@ -38,16 +38,8 @@ defmodule FrameworkBenchmarks.Handlers.Update do
38
38
|> FrameworkBenchmarks.Repo . update! ( )
39
39
end )
40
40
)
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! ( )
51
43
52
44
conn
53
45
|> Plug.Conn . put_resp_content_type ( "application/json" )
Original file line number Diff line number Diff line change 1
1
defmodule FrameworkBenchmarks.Models.World do
2
2
use Ecto.Schema
3
3
4
+ @ derive { Jason.Encoder , only: [ :id , :randomnumber ] }
4
5
schema "world" do
5
6
field ( :randomnumber , :integer )
6
7
end
You can’t perform that action at this time.
0 commit comments