Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
4,581 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ erl_crash.dump | |
*.beam | ||
.DS_Store | ||
/docs/all.json | ||
/bench/snapshots | ||
/bench/graphs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Witchcraft.Applicative.FunctionBench do | ||
use Benchfella | ||
use Witchcraft.Applicative | ||
|
||
######### | ||
# Setup # | ||
######### | ||
|
||
# ---------- # | ||
# Data Types # | ||
# ---------- # | ||
|
||
def fun(x), do: "#{inspect x}-#{inspect x}" | ||
|
||
# -------------- # | ||
# Test Functions # | ||
# -------------- # | ||
|
||
defp twice(f), do: fn x -> x |> f.() |> f.() end | ||
defp to_fun(x), do: of(&fun/1).(x) | ||
|
||
############### | ||
# Applicative # | ||
############### | ||
|
||
bench "of/1", do: to_fun(42) | ||
bench "of/2", do: of(&fun/1, &twice/1) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Witchcraft.Applicative.ListBench do | ||
use Benchfella | ||
use Witchcraft.Applicative | ||
|
||
######### | ||
# Setup # | ||
######### | ||
|
||
# ---------- # | ||
# Data Types # | ||
# ---------- # | ||
|
||
@to_wrap 11..100 |> Enum.to_list() |> Enum.shuffle() | ||
@list 99..999 |> Enum.to_list() |> Enum.shuffle() | ||
|
||
# -------------- # | ||
# Test Functions # | ||
# -------------- # | ||
|
||
defp to_list(x), do: of(@list).(x) | ||
|
||
############### | ||
# Applicative # | ||
############### | ||
|
||
bench "of/1", do: to_list(@to_wrap) | ||
bench "of/2", do: of(@list, @to_wrap) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Witchcraft.Applicative.TupleBench do | ||
use Benchfella | ||
use Witchcraft.Applicative | ||
|
||
######### | ||
# Setup # | ||
######### | ||
|
||
# ---------- # | ||
# Data Types # | ||
# ---------- # | ||
|
||
@to_wrap 11..100 |> Enum.to_list() |> Enum.shuffle() | ||
@tuple 99..999 |> Enum.to_list() |> Enum.shuffle() |> List.to_tuple() | ||
|
||
# -------------- # | ||
# Test Functions # | ||
# -------------- # | ||
|
||
defp to_tuple(x), do: of(@tuple).(x) | ||
|
||
############### | ||
# Applicative # | ||
############### | ||
|
||
bench "of/1", do: to_tuple(@to_wrap) | ||
bench "of/2", do: of(@tuple, @to_wrap) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
defmodule Witchcraft.Apply.FunBench do | ||
use Benchfella | ||
use Witchcraft.Apply | ||
|
||
######### | ||
# Setup # | ||
######### | ||
|
||
# ---------- # | ||
# Data Types # | ||
# ---------- # | ||
|
||
defp fun(x, y, z), do: x + y * z | ||
defp fun(z), do: fn x -> fn y -> x + y + z end end | ||
|
||
defp slow_fun(z) do | ||
Process.sleep(20) | ||
fn(x, y) -> | ||
x + y * z | ||
end | ||
end | ||
|
||
defp slow_fun(x, y, z) do | ||
Process.sleep(20) | ||
x + y * z | ||
end | ||
|
||
######### | ||
# Apply # | ||
######### | ||
|
||
# ==== # | ||
# 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 <<~/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 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 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 "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 "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_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) -> | ||
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) -> | ||
Process.sleep(20) | ||
x + y + z | ||
end) | ||
end | ||
|
||
# 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) -> | ||
Process.sleep(20) | ||
w + x + y + z | ||
end) | ||
end | ||
|
||
bench "!!! over/3" do | ||
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) -> | ||
Process.sleep(20) | ||
x + y + z | ||
end | ||
|> over(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end) | ||
end | ||
|
||
# So slow | ||
bench "!!! over/5" do | ||
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_lift/3" do | ||
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) -> | ||
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) | ||
end | ||
|
||
bench "!!! async_over/3" do | ||
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) -> | ||
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) -> | ||
Process.sleep(20) | ||
w + x + y + z | ||
end | ||
|> async_over(fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end, fn x -> fun(x) end) | ||
end | ||
end |
Oops, something went wrong.