forked from elixir-ecto/ecto_sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_bench.exs
More file actions
52 lines (44 loc) · 2.23 KB
/
Copy pathload_bench.exs
File metadata and controls
52 lines (44 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -----------------------------------Goal--------------------------------------
# Compare the implementation of loading raw database data into Ecto structures by
# the different database adapters
# -------------------------------Description-----------------------------------
# Repo.load/2 is an important step of a database query.
# This benchmark tracks performance of loading "raw" data into ecto structures
# Raw data can be in different types (e.g. keyword lists, maps), in this tests
# we benchmark against map inputs
# ----------------------------Factors(don't change)---------------------------
# Different adapters supported by Ecto, each one has its own implementation that
# is tested against different inputs
# ----------------------------Parameters(change)-------------------------------
# Different sizes of raw data(small, medium, big) and different attribute types
# such as UUID, Date and Time fetched from the database and needs to be
# loaded into Ecto structures.
Code.require_file("../../support/setup.exs", __DIR__)
alias Ecto.Bench.User
inputs = %{
"1. Small 1 Thousand" =>
1..1_000 |> Stream.map(fn _ -> %{name: "Alice", email: "email@email.com"} end),
"2. Medium 100 Thousand" =>
1..100_000 |> Stream.map(fn _ -> %{name: "Alice", email: "email@email.com"} end),
"3. Big 1 Million" =>
1..1_000_000 |> Stream.map(fn _ -> %{name: "Alice", email: "email@email.com"} end),
"4. Time attr" =>
1..100_000 |> Stream.map(fn _ -> %{name: "Alice", time_attr: ~T[21:25:04.361140]} end),
"5. Date attr" => 1..100_000 |> Stream.map(fn _ -> %{name: "Alice", date_attr: ~D[2018-06-20]} end),
"6. NaiveDateTime attr" =>
1..100_000
|> Stream.map(fn _ -> %{name: "Alice", naive_datetime_attr: ~N[2019-06-20 21:32:07.424178]} end),
"7. UUID attr" =>
1..100_000
|> Stream.map(fn _ -> %{name: "Alice", uuid: Ecto.UUID.bingenerate()} end)
}
jobs = %{
"Control" => fn stream -> stream |> Stream.map(fn _data -> true end) |> Stream.run() end,
"Pg Loader" => fn stream -> stream |> Stream.map(&Ecto.Bench.PgRepo.load(User, &1)) |> Stream.run() end,
"MyXQL Loader" => fn data -> Enum.map(data, &Ecto.Bench.MyXQLRepo.load(User, &1)) end
}
Benchee.run(
jobs,
inputs: inputs,
formatters: Ecto.Bench.Helper.formatters("load")
)