-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Aja.Enum.sum_by/2 and Aja.Enum.product_by/2
- Loading branch information
Showing
8 changed files
with
191 additions
and
15 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
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,12 @@ | ||
list = Enum.map(1..1000, &(1 + rem(&1, 3))) | ||
vector = Aja.Vector.new(list) | ||
|
||
Benchee.run(%{ | ||
"Aja.Enum.product_by/2 (vector)" => fn -> Aja.Enum.product_by(vector, & &1) end, | ||
"Enum.product_by/2 (vector)" => fn -> Enum.product_by(vector, & &1) end, | ||
"Aja.Enum.reduce/3 (vector)" => fn -> Aja.Enum.reduce(vector, 1, &*/2) end, | ||
"Enum.product_by/2 (list)" => fn -> Enum.product_by(list, & &1) end, | ||
# for comparison: | ||
"Enum.product(list)" => fn -> Enum.product(list) end, | ||
"Aja.Enum.product(vector)" => fn -> Aja.Enum.product(vector) 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,41 @@ | ||
Operating System: macOS | ||
CPU Information: Apple M1 | ||
Number of Available Cores: 8 | ||
Available memory: 16 GB | ||
Elixir 1.18.0-rc.0 | ||
Erlang 27.0 | ||
JIT enabled: true | ||
|
||
Benchmark suite executing with the following configuration: | ||
warmup: 2 s | ||
time: 5 s | ||
memory time: 0 ns | ||
reduction time: 0 ns | ||
parallel: 1 | ||
inputs: none specified | ||
Estimated total run time: 42 s | ||
|
||
Benchmarking Aja.Enum.product(vector) ... | ||
Benchmarking Aja.Enum.product_by/2 (vector) ... | ||
Benchmarking Aja.Enum.reduce/3 (vector) ... | ||
Benchmarking Enum.product(list) ... | ||
Benchmarking Enum.product_by/2 (list) ... | ||
Benchmarking Enum.product_by/2 (vector) ... | ||
Calculating statistics... | ||
Formatting results... | ||
|
||
Name ips average deviation median 99th % | ||
Aja.Enum.product(vector) 90.68 K 11.03 μs ±22.83% 10.92 μs 12.79 μs | ||
Enum.product(list) 85.90 K 11.64 μs ±14.89% 11.25 μs 14.63 μs | ||
Aja.Enum.product_by/2 (vector) 80.01 K 12.50 μs ±16.89% 12 μs 18.63 μs | ||
Enum.product_by/2 (list) 74.35 K 13.45 μs ±44.35% 12.83 μs 23.63 μs | ||
Aja.Enum.reduce/3 (vector) 73.37 K 13.63 μs ±32.29% 13.25 μs 19.17 μs | ||
Enum.product_by/2 (vector) 51.72 K 19.34 μs ±20.57% 18.67 μs 25.42 μs | ||
|
||
Comparison: | ||
Aja.Enum.product(vector) 90.68 K | ||
Enum.product(list) 85.90 K - 1.06x slower +0.61 μs | ||
Aja.Enum.product_by/2 (vector) 80.01 K - 1.13x slower +1.47 μs | ||
Enum.product_by/2 (list) 74.35 K - 1.22x slower +2.42 μs | ||
Aja.Enum.reduce/3 (vector) 73.37 K - 1.24x slower +2.60 μs | ||
Enum.product_by/2 (vector) 51.72 K - 1.75x slower +8.31 μs |
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,12 @@ | ||
list = Enum.map(1..1000, &(1 + rem(&1, 3))) | ||
vector = Aja.Vector.new(list) | ||
|
||
Benchee.run(%{ | ||
"Aja.Enum.sum_by/2 (vector)" => fn -> Aja.Enum.sum_by(vector, & &1) end, | ||
"Aja.Enum.sum_by/2 (list)" => fn -> Aja.Enum.sum_by(list, & &1) end, | ||
"Enum.sum_by/2 (vector)" => fn -> Enum.sum_by(vector, & &1) end, | ||
"Aja.Enum.reduce/3 (vector)" => fn -> Aja.Enum.reduce(vector, 0, &+/2) end, | ||
"Enum.sum_by/2 (list)" => fn -> Enum.sum_by(list, & &1) end, | ||
# for comparison: | ||
":lists.sum/1" => fn -> :lists.sum(list) 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,41 @@ | ||
Operating System: macOS | ||
CPU Information: Apple M1 | ||
Number of Available Cores: 8 | ||
Available memory: 16 GB | ||
Elixir 1.18.0-rc.0 | ||
Erlang 27.0 | ||
JIT enabled: true | ||
|
||
Benchmark suite executing with the following configuration: | ||
warmup: 2 s | ||
time: 5 s | ||
memory time: 0 ns | ||
reduction time: 0 ns | ||
parallel: 1 | ||
inputs: none specified | ||
Estimated total run time: 42 s | ||
|
||
Benchmarking :lists.sum/1 ... | ||
Benchmarking Aja.Enum.reduce/3 (vector) ... | ||
Benchmarking Aja.Enum.sum_by/2 (list) ... | ||
Benchmarking Aja.Enum.sum_by/2 (vector) ... | ||
Benchmarking Enum.sum_by/2 (list) ... | ||
Benchmarking Enum.sum_by/2 (vector) ... | ||
Calculating statistics... | ||
Formatting results... | ||
|
||
Name ips average deviation median 99th % | ||
:lists.sum/1 519.20 K 1.93 μs ±264.77% 1.88 μs 2.08 μs | ||
Aja.Enum.sum_by/2 (vector) 393.70 K 2.54 μs ±1997.47% 2.33 μs 2.63 μs | ||
Aja.Enum.sum_by/2 (list) 312.38 K 3.20 μs ±250.41% 3.21 μs 3.38 μs | ||
Enum.sum_by/2 (list) 305.42 K 3.27 μs ±278.26% 3.21 μs 3.58 μs | ||
Aja.Enum.reduce/3 (vector) 147.91 K 6.76 μs ±109.40% 6.71 μs 7.04 μs | ||
Enum.sum_by/2 (vector) 121.08 K 8.26 μs ±79.69% 7.92 μs 12.92 μs | ||
|
||
Comparison: | ||
:lists.sum/1 519.20 K | ||
Aja.Enum.sum_by/2 (vector) 393.70 K - 1.32x slower +0.61 μs | ||
Aja.Enum.sum_by/2 (list) 312.38 K - 1.66x slower +1.28 μs | ||
Enum.sum_by/2 (list) 305.42 K - 1.70x slower +1.35 μs | ||
Aja.Enum.reduce/3 (vector) 147.91 K - 3.51x slower +4.83 μs | ||
Enum.sum_by/2 (vector) 121.08 K - 4.29x slower +6.33 μs |
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
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