Skip to content

Commit

Permalink
Run mix format bench/**/*.exs
Browse files Browse the repository at this point in the history
  • Loading branch information
florius0 authored and QuinnWilton committed Feb 3, 2022
1 parent dc967fc commit b325db9
Show file tree
Hide file tree
Showing 59 changed files with 1,135 additions and 999 deletions.
7 changes: 3 additions & 4 deletions bench/witchcraft/applicative/function_bench.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Witchcraft.Applicative.FunctionBench do
# Data Types #
# ---------- #

def fun(x), do: "#{inspect x}-#{inspect x}"
def fun(x), do: "#{inspect(x)}-#{inspect(x)}"

# -------------- #
# Test Functions #
Expand All @@ -25,7 +25,6 @@ defmodule Witchcraft.Applicative.FunctionBench do
# Applicative #
###############

bench "of/1", do: to_fun(42)
bench "of/2", do: of(&fun/1, &twice/1)

bench("of/1", do: to_fun(42))
bench("of/2", do: of(&fun/1, &twice/1))
end
5 changes: 2 additions & 3 deletions bench/witchcraft/applicative/list_bench.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule Witchcraft.Applicative.ListBench do
# Applicative #
###############

bench "of/1", do: to_list(@to_wrap)
bench "of/2", do: of(@list, @to_wrap)

bench("of/1", do: to_list(@to_wrap))
bench("of/2", do: of(@list, @to_wrap))
end
5 changes: 2 additions & 3 deletions bench/witchcraft/applicative/tuple_bench.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule Witchcraft.Applicative.TupleBench do
# Applicative #
###############

bench "of/1", do: to_tuple(@to_wrap)
bench "of/2", do: of(@tuple, @to_wrap)

bench("of/1", do: to_tuple(@to_wrap))
bench("of/2", do: of(@tuple, @to_wrap))
end
138 changes: 93 additions & 45 deletions bench/witchcraft/apply/function_bench.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule Witchcraft.Apply.FunBench do
use Benchfella
use Witchcraft.Apply


#########
# Setup #
#########
Expand All @@ -18,7 +17,8 @@ defmodule Witchcraft.Apply.FunBench do

defp slow_fun(z) do
Process.sleep(20)
fn(x, y) ->

fn x, y ->
x + y * z
end
end
Expand All @@ -36,56 +36,95 @@ defmodule Witchcraft.Apply.FunBench do
# Data #
# ==== #

bench "data convey/2", do: fn x -> fun(x) end |> convey(fn x -> fun(x) end)
bench "data ap/2", do: fn x -> fun(x) end |> ap(fn x -> fun(x) end)
bench("data convey/2", do: fn x -> fun(x) end |> convey(fn x -> fun(x) end))
bench("data ap/2", do: fn x -> fun(x) end |> ap(fn x -> fun(x) end))

bench("data <<~/2", do: fn x -> fun(x) end <<~ fn x -> fun(x) end)
bench("data <<~/2", do: fn x -> fun(x) end <<~ fn x -> fun(x) end)

bench("data ~>>/2", do: fn x -> fun(x) end ~>> fn x -> fun(x) end)
bench("data ~>>/2", do: fn x -> fun(x) end ~>> fn x -> fun(x) end)

bench "data <<~/2", do: fn x -> fun(x) end <<~ fn x -> fun(x) end
bench "data <<~/2", do: fn x -> fun(x) end <<~ fn x -> fun(x) end
bench("data provide/2", do: fn x -> fun(x) end |> provide(fn x -> fun(x) end))
bench("data supply/2", do: fn x -> fun(x) end |> supply(fn x -> fun(x) end))

bench "data ~>>/2", do: fn x -> fun(x) end ~>> fn x -> fun(x) end
bench "data ~>>/2", do: fn x -> fun(x) end ~>> fn x -> fun(x) end
bench("data lift/3", do: lift(fn x -> fun(x) end, fn x -> fun(x) end, &+/2))

bench "data provide/2", do: fn x -> fun(x) end |> provide(fn x -> fun(x) end)
bench "data supply/2", do: fn x -> fun(x) end |> supply(fn x -> fun(x) end)
bench("data lift/4",
do: lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x, y, z -> x + y + z end)
)

bench "data lift/3", do: lift(fn x -> fun(x) end, fn x -> fun(x) end, &+/2)
bench "data lift/4", do: lift(fn x -> fun(x) end, fn x -> fun(x) end, fn(x, y, z) -> x + y + z end)
bench "data lift/5", do: lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn(w, x, y, z) -> w + x + y + z end)
bench("data lift/5",
do:
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn w, x, y, z ->
w + x + y + z
end)
)

bench "data over/3", do: over(&+/2, fn x -> fun(x) end, fn x -> fun(x) end)
bench "data over/4", do: over(fn(x, y, z) -> x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end)
bench "data over/5", do: over(fn(w, x, y, z) -> w + x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end)
bench("data over/3", do: over(&+/2, fn x -> fun(x) end, fn x -> fun(x) end))

bench "following/2", do: fn x -> fun(x) end |> following(fn x -> fun(x) end)
bench "then/2", do: fn x -> fun(x) end |> then(fn x -> fun(x) end)
bench("data over/4",
do: over(fn x, y, z -> x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end)
)

bench("data over/5",
do:
over(fn w, x, y, z -> w + x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end, fn x ->
fun(x)
end)
)

bench("following/2", do: fn x -> fun(x) end |> following(fn x -> fun(x) end))
bench("then/2", do: fn x -> fun(x) end |> then(fn x -> fun(x) end))

# ----- #
# Async #
# ----- #

bench "data async_convey/2", do: fn x -> fun(x) end |> async_convey(fn x -> fun(x) end)
bench "data async_ap/2", do: fn x -> fun(x) end |> async_ap(fn x -> fun(x) end)
bench("data async_convey/2", do: fn x -> fun(x) end |> async_convey(fn x -> fun(x) end))
bench("data async_ap/2", do: fn x -> fun(x) end |> async_ap(fn x -> fun(x) end))

bench("async_lift/3", do: async_lift(fn x -> fun(x) end, fn x -> fun(x) end, &+/2))

bench "async_lift/3", do: async_lift(fn x -> fun(x) end, fn x -> fun(x) end, &+/2)
bench "async_lift/4", do: async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn(x, y, z) -> x + y + z end)
bench "async_lift/5", do: async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn(w, x, y, z) -> w + x + y + z end)
bench("async_lift/4",
do: async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x, y, z -> x + y + z end)
)

bench "async_over/3", do: async_over(&+/2, fn x -> fun(x) end, fn x -> fun(x) end)
bench "async_over/4", do: async_over(fn(x, y, z) -> x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end)
bench "async_over/5", do: async_over(fn(w, x, y, z) -> w + x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end)
bench("async_lift/5",
do:
async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn w, x, y, z ->
w + x + y + z
end)
)

bench "!!! convey/2", do: fn x -> fun(x) end |> convey(fn y -> slow_fun(y) end)
bench "!!! ap/2", do: fn y -> slow_fun(y) end |> ap(fn x -> fun(x) end)
bench("async_over/3", do: async_over(&+/2, fn x -> fun(x) end, fn x -> fun(x) end))

bench("async_over/4",
do: async_over(fn x, y, z -> x + y + z end, fn x -> fun(x) end, fn x -> fun(x) end)
)

bench("async_over/5",
do:
async_over(
fn w, x, y, z -> w + x + y + z end,
fn x -> fun(x) end,
fn x -> fun(x) end,
fn x -> fun(x) end
)
)

bench("!!! convey/2", do: fn x -> fun(x) end |> convey(fn y -> slow_fun(y) end))
bench("!!! ap/2", do: fn y -> slow_fun(y) end |> ap(fn x -> fun(x) end))

bench "!!! lift/3" do
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn(x, y) ->
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x, y ->
Process.sleep(20)
x + y
end)
end

bench "!!! lift/4" do
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn(x, y, z) ->
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x, y, z ->
Process.sleep(20)
x + y + z
end)
Expand All @@ -94,22 +133,25 @@ defmodule Witchcraft.Apply.FunBench do
# also very slow, due to exponential complexity of multiple fun dimensions
# 50^4 = 6_250_000 items to process
bench "!!! lift/5" do
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn(w, x, y, z) ->
lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn w,
x,
y,
z ->
Process.sleep(20)
w + x + y + z
end)
end

bench "!!! over/3" do
fn(x, y) ->
fn x, y ->
Process.sleep(20)
x + y
end
|> over(fn x -> fun(x) end, fn x -> fun(x) end)
end

bench "!!! over/4" do
fn(x, y, z) ->
fn x, y, z ->
Process.sleep(20)
x + y + z
end
Expand All @@ -118,55 +160,61 @@ defmodule Witchcraft.Apply.FunBench do

# So slow
bench "!!! over/5" do
fn(w, x, y, z) ->
fn w, x, y, z ->
Process.sleep(20)
w + x + y + z
end
|> over(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end)
end

bench "!!! async_convey/2", do: fn x -> fun(x) end |> async_convey(fn y -> slow_fun(y) end)
bench "!!! async_ap/2", do: fn y -> slow_fun(y) end |> async_ap(fn x -> fun(x) end)
bench("!!! async_convey/2", do: fn x -> fun(x) end |> async_convey(fn y -> slow_fun(y) end))
bench("!!! async_ap/2", do: fn y -> slow_fun(y) end |> async_ap(fn x -> fun(x) end))

bench "!!! async_lift/3" do
async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn(x, y) ->
async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x, y ->
Process.sleep(20)
x + y
end)
end

bench "!!! async_lift/4" do
async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn(x, y, z) ->
async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x, y, z ->
Process.sleep(20)
x + y + z
end)
end

bench "!!! async_lift/5" do
async_lift(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn(w, x, y, z) ->
Process.sleep(20)
w + x + y + z
end)
async_lift(
fn x -> fun(x) end,
fn x -> fun(x) end,
fn x -> fun(x) end,
fn x -> fun(x) end,
fn w, x, y, z ->
Process.sleep(20)
w + x + y + z
end
)
end

bench "!!! async_over/3" do
fn(x, y) ->
fn x, y ->
Process.sleep(20)
x + y
end
|> async_over(fn x -> fun(x) end, fn x -> fun(x) end)
end

bench "!!! async_over/4" do
fn(x, y, z) ->
fn x, y, z ->
Process.sleep(20)
x + y + z
end
|> async_over(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end)
end

bench "!!! async_over/5" do
fn(w, x, y, z) ->
fn w, x, y, z ->
Process.sleep(20)
w + x + y + z
end
Expand Down
Loading

0 comments on commit b325db9

Please sign in to comment.