Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created May 9, 2024 06:29
Show Gist options
  • Save sorentwo/3c85f71d84124b8a1fca69ace647f4cb to your computer and use it in GitHub Desktop.
Save sorentwo/3c85f71d84124b8a1fca69ace647f4cb to your computer and use it in GitHub Desktop.
OTP 26.2.5 select performance with a map in the key
Operating System: macOS
CPU Information: Apple M3 Pro
Number of Available Cores: 12
Available memory: 36 GB
Elixir 1.16.1
Erlang 26.2.4
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: 21 s
Benchmarking lookup ...
Benchmarking select ...
Benchmarking select_reverse ...
Calculating statistics...
Formatting results...
Name ips average deviation median 99th %
lookup 1587.69 K 0.63 μs ±1754.84% 0.63 μs 0.79 μs
select 930.43 K 1.07 μs ±366.70% 1.04 μs 1.25 μs
select_reverse 915.83 K 1.09 μs ±349.99% 1.08 μs 1.29 μs
Comparison:
lookup 1587.69 K
select 930.43 K - 1.71x slower +0.44 μs
select_reverse 915.83 K - 1.73x slower +0.46 μs
Operating System: macOS
CPU Information: Apple M3 Pro
Number of Available Cores: 12
Available memory: 36 GB
Elixir 1.16.1
Erlang 26.2.5
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: 21 s
Benchmarking lookup ...
Benchmarking select ...
Benchmarking select_reverse ...
Calculating statistics...
Formatting results...
Name ips average deviation median 99th %
lookup 1.62 M 616.07 ns ±1798.74% 584 ns 791 ns
select_reverse 1.21 M 823.61 ns ±1503.76% 667 ns 958 ns
select 0.00100 M 995660.57 ns ±2.84% 982750 ns 1058731.74 ns
Comparison:
lookup 1.62 M
select_reverse 1.21 M - 1.34x slower +207.54 ns
select 0.00100 M - 1616.16x slower +995044.50 ns
tab = :ets.new(
:metrics, [
:compressed,
:ordered_set,
:protected,
read_concurrency: true
])
sys_time = System.system_time(:second)
labels = %{"a" => 1, "b" => 2}
for offset <- 0..10_000 do
time = sys_time - offset
:ets.insert(tab, {{"exec_time", labels, time}, time, %{}})
end
key = {"exec_time", labels, sys_time - 1}
match = {key, sys_time - 1, :"$1"}
Benchee.run(%{
"lookup" => fn ->
:ets.lookup(tab, key)
end,
"select" => fn ->
:ets.select(tab, [{match, [], [:"$1"]}], 1)
end,
"select_reverse" => fn ->
:ets.select_reverse(tab, [{match, [], [:"$1"]}], 1)
end
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment