Skip to content

Instantly share code, notes, and snippets.

@bryanenders
Last active May 6, 2021 20:05
Show Gist options
  • Save bryanenders/d86bd875953db4432a242634a260a85d to your computer and use it in GitHub Desktop.
Save bryanenders/d86bd875953db4432a242634a260a85d to your computer and use it in GitHub Desktop.
integer_pairs =
for a <- 1..1_000,
b <- 1..1_000,
do: [a, b]
Benchee.run(
%{
"===" => &Enum.map(&1, fn [a, b] -> a === b end),
"==" => &Enum.map(&1, fn [a, b] -> a == b end),
"!==" => &Enum.map(&1, fn [a, b] -> a !== b end),
"!=" => &Enum.map(&1, fn [a, b] -> a != b end),
"<" => &Enum.map(&1, fn [a, b] -> a < b end),
">" => &Enum.map(&1, fn [a, b] -> a > b end)
},
inputs: %{
"Integers" => integer_pairs,
"Floats" => Enum.map(integer_pairs, fn pair -> Enum.map(pair, &:erlang.float/1) end),
"Mixed" => Enum.map(integer_pairs, fn [a, b] -> [a, :erlang.float(b)] end)
}
)
# Operating System: macOS
# CPU Information: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
# Number of Available Cores: 16
# Available memory: 32 GB
# Elixir 1.11.2
# Erlang 23.1.1
# Benchmark suite executing with the following configuration:
# warmup: 5 s
# time: 10 s
# memory time: 0 ns
# parallel: 1
# inputs: Floats, Integers, Mixed
# Estimated total run time: 4.50 min
# Benchmarking != with input Floats...
# Benchmarking != with input Integers...
# Benchmarking != with input Mixed...
# Benchmarking !== with input Floats...
# Benchmarking !== with input Integers...
# Benchmarking !== with input Mixed...
# Benchmarking < with input Floats...
# Benchmarking < with input Integers...
# Benchmarking < with input Mixed...
# Benchmarking == with input Floats...
# Benchmarking == with input Integers...
# Benchmarking == with input Mixed...
# Benchmarking === with input Floats...
# Benchmarking === with input Integers...
# Benchmarking === with input Mixed...
# Benchmarking > with input Floats...
# Benchmarking > with input Integers...
# Benchmarking > with input Mixed...
# ##### With input Floats #####
# Name ips average deviation median 99th %
# != 12.66 78.98 ms ±22.15% 74.81 ms 217.19 ms
# < 12.63 79.15 ms ±20.38% 75.32 ms 205.36 ms
# == 12.44 80.40 ms ±21.11% 77.12 ms 215.14 ms
# > 12.27 81.50 ms ±21.73% 78.28 ms 225.63 ms
# === 12.14 82.35 ms ±21.29% 78.63 ms 225.97 ms
# !== 12.14 82.36 ms ±23.07% 78.86 ms 238.73 ms
# Comparison:
# != 12.66
# < 12.63 - 1.00x slower +0.163 ms
# == 12.44 - 1.02x slower +1.42 ms
# > 12.27 - 1.03x slower +2.52 ms
# === 12.14 - 1.04x slower +3.36 ms
# !== 12.14 - 1.04x slower +3.38 ms
# ##### With input Integers #####
# Name ips average deviation median 99th %
# != 12.29 81.34 ms ±19.47% 76.60 ms 193.37 ms
# < 12.28 81.44 ms ±20.90% 79.11 ms 205.85 ms
# == 11.92 83.86 ms ±20.20% 79.31 ms 210.60 ms
# > 11.88 84.20 ms ±20.36% 79.02 ms 216.44 ms
# !== 11.52 86.83 ms ±19.90% 83.72 ms 220.57 ms
# === 11.33 88.28 ms ±20.20% 82.51 ms 231.59 ms
# Comparison:
# != 12.29
# < 12.28 - 1.00x slower +0.0973 ms
# == 11.92 - 1.03x slower +2.52 ms
# > 11.88 - 1.04x slower +2.86 ms
# !== 11.52 - 1.07x slower +5.49 ms
# === 11.33 - 1.09x slower +6.94 ms
# ##### With input Mixed #####
# Name ips average deviation median 99th %
# !== 11.45 87.30 ms ±14.93% 88.98 ms 162.15 ms
# != 11.37 87.98 ms ±19.69% 84.48 ms 237.04 ms
# < 11.28 88.67 ms ±19.55% 86.21 ms 236.33 ms
# === 11.18 89.45 ms ±14.69% 86.81 ms 174.11 ms
# > 10.56 94.69 ms ±15.40% 92.73 ms 189.09 ms
# == 10.50 95.20 ms ±14.58% 94.25 ms 185.44 ms
# Comparison:
# !== 11.45
# != 11.37 - 1.01x slower +0.68 ms
# < 11.28 - 1.02x slower +1.37 ms
# === 11.18 - 1.02x slower +2.15 ms
# > 10.56 - 1.08x slower +7.38 ms
# == 10.50 - 1.09x slower +7.89 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment