-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark module and top level differences
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
list = Enum.to_list(1..100) | ||
|
||
defmodule Compiled do | ||
def comprehension(list) do | ||
for x <- list, rem(x, 2) == 1, do: x + 1 | ||
end | ||
end | ||
|
||
# Top level definitions used to be slower than module definitions. | ||
# These were due to disabled compiler optimizations (no_bool_opt, no_ssa_opt) | ||
# and have been fixed from elixir 1.16.0-rc.1: | ||
# https://github.com/elixir-lang/elixir/commit/aabe46536e021da88de39bc5c82c90d97b0604ec#diff-1f4ed234972cb699fe6dc400f3bbf57f72919ef587ba6b1a43441c8b784b0cfb | ||
|
||
Benchee.run(%{ | ||
"module (optimized)" => fn -> Compiled.comprehension(list) end, | ||
"top_level (non-optimized)" => fn -> for x <- list, rem(x, 2) == 1, do: x + 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,26 @@ | ||
Operating System: macOS | ||
CPU Information: Apple M1 | ||
Number of Available Cores: 8 | ||
Available memory: 16 GB | ||
Elixir 1.15.6 | ||
Erlang 26.1.1 | ||
|
||
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: 14 s | ||
|
||
Benchmarking module (optimized) ... | ||
Benchmarking top_level (non-optimized) ... | ||
|
||
Name ips average deviation median 99th % | ||
module (optimized) 1.74 M 576.11 ns ±4796.26% 500 ns 667 ns | ||
top_level (non-optimized) 1.16 M 863.56 ns ±1966.89% 792 ns 958 ns | ||
|
||
Comparison: | ||
module (optimized) 1.74 M | ||
top_level (non-optimized) 1.16 M - 1.50x slower +287.45 ns |
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,26 @@ | ||
Operating System: macOS | ||
CPU Information: Apple M1 | ||
Number of Available Cores: 8 | ||
Available memory: 16 GB | ||
Elixir 1.16.0-rc.1 | ||
Erlang 26.1.1 | ||
|
||
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: 14 s | ||
|
||
Benchmarking module (optimized) ... | ||
Benchmarking top_level (non-optimized) ... | ||
|
||
Name ips average deviation median 99th % | ||
top_level (non-optimized) 1.77 M 565.93 ns ±3945.40% 500 ns 667 ns | ||
module (optimized) 1.72 M 580.88 ns ±4537.27% 500 ns 667 ns | ||
|
||
Comparison: | ||
top_level (non-optimized) 1.77 M | ||
module (optimized) 1.72 M - 1.03x slower +14.95 ns |