minhajuddin

minhajuddin

Benchmarking lookup time for map vs ets

I did a quick benchmark of lookup time for map vs ets as I am working with a lot of ETL stuff. ets is very convenient as you can communicate with it from other processes just by using named tables. And the performance difference between these doesn’t seem huge (lookup times for ets is 1 to 2x of map lookup times).

Here are the logs for your perusal. The benchmarking code can be found at GitHub - minhajuddin/lookup_bench · GitHub . Would love to hear your thoughts :slight_smile:

In the log, the first number is the number of records in the map/ets table and the second number is the number of lookups, so ‘ets_1000_100’ means it has 1000 records in the ets table and we are performing 100 lookups

There is a bug in the code which incorrectly reports the number of lookups when the size of the map/ets table is less than the number of keys, in this scenario the number of lookups is actually equal to the number of keys in the map/ets table

15:05:09.922 [debug] starting benchmark

15:05:09.922 [debug] loading data
Erlang/OTP 19 [erts-8.2] [source-fbd2db2] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.4.0
Benchmark suite executing with the following configuration:
warmup: 2.0s
time: 5.0s
parallel: 1
inputs: none specified
Estimated total run time: 14.0s

Benchmarking ets_100_100...
Benchmarking map_100_100...

Name                  ips        average  deviation         median
map_100_100      100.55 K        9.95 μs    ±44.35%       10.00 μs
ets_100_100       52.12 K       19.19 μs    ±57.85%       17.00 μs

Comparison:
map_100_100      100.55 K
ets_100_100       52.12 K - 1.93x slower

- - -

Benchmarking ets_100_1000...
Benchmarking map_100_1000...

Name                   ips        average  deviation         median
map_100_1000       99.89 K       10.01 μs    ±42.19%       10.00 μs
ets_100_1000       52.50 K       19.05 μs    ±55.80%       17.00 μs

Comparison:
map_100_1000       99.89 K
ets_100_1000       52.50 K - 1.90x slower

- - -

Benchmarking ets_100_10000...
Benchmarking map_100_10000...

Name                    ips        average  deviation         median
map_100_10000      100.04 K       10.00 μs    ±40.33%       10.00 μs
ets_100_10000       52.72 K       18.97 μs    ±56.81%       17.00 μs

Comparison:
map_100_10000      100.04 K
ets_100_10000       52.72 K - 1.90x slower

- - -

Benchmarking ets_1000_100...
Benchmarking map_1000_100...

Name                   ips        average  deviation         median
map_1000_100       85.03 K       11.76 μs    ±51.86%       11.00 μs
ets_1000_100       45.03 K       22.21 μs    ±44.35%       20.00 μs

Comparison:
map_1000_100       85.03 K
ets_1000_100       45.03 K - 1.89x slower

- - -

Benchmarking ets_1000_1000...
Benchmarking map_1000_1000...

Name                    ips        average  deviation         median
map_1000_1000        8.58 K      116.58 μs    ±12.33%      110.00 μs
ets_1000_1000        3.93 K      254.60 μs    ±14.07%      247.00 μs

Comparison:
map_1000_1000        8.58 K
ets_1000_1000        3.93 K - 2.18x slower

- - -

Benchmarking ets_1000_10000...
Benchmarking map_1000_10000...

Name                     ips        average  deviation         median
map_1000_10000        8.74 K      114.38 μs    ±11.29%      108.00 μs
ets_1000_10000        3.94 K      253.52 μs    ±14.61%      247.00 μs

Comparison:
map_1000_10000        8.74 K
ets_1000_10000        3.94 K - 2.22x slower

- - -

Benchmarking ets_10000_100...
Benchmarking map_10000_100...

Name                    ips        average  deviation         median
map_10000_100       72.80 K       13.74 μs   ±102.80%       13.00 μs
ets_10000_100       41.67 K       24.00 μs    ±39.73%       22.00 μs

Comparison:
map_10000_100       72.80 K
ets_10000_100       41.67 K - 1.75x slower

- - -

Benchmarking ets_10000_1000...
Benchmarking map_10000_1000...

Name                     ips        average  deviation         median
map_10000_1000        5.89 K      169.64 μs    ±31.67%      151.00 μs
ets_10000_1000        3.04 K      329.03 μs    ±14.20%      322.00 μs

Comparison:
map_10000_1000        5.89 K
ets_10000_1000        3.04 K - 1.94x slower

- - -

Benchmarking ets_10000_10000...
Benchmarking map_10000_10000...

Name                      ips        average  deviation         median
map_10000_10000        583.12        1.71 ms    ±26.31%        1.48 ms
ets_10000_10000        269.62        3.71 ms    ±33.27%        3.04 ms

Comparison:
map_10000_10000        583.12
ets_10000_10000        269.62 - 2.16x slower

- - -

Benchmarking ets_100000_100...
Benchmarking map_100000_100...

Name                     ips        average  deviation         median
map_100000_100       43.00 K       23.26 μs  ±1400.38%       14.00 μs
ets_100000_100       42.37 K       23.60 μs    ±39.66%       21.00 μs

Comparison:
map_100000_100       43.00 K
ets_100000_100       42.37 K - 1.01x slower

- - -

Benchmarking ets_100000_1000...
Benchmarking map_100000_1000...

Name                      ips        average  deviation         median
map_100000_1000        3.01 K      332.13 μs   ±323.60%      210.00 μs
ets_100000_1000        2.75 K      363.27 μs    ±15.39%      355.00 μs

Comparison:
map_100000_1000        3.01 K
ets_100000_1000        2.75 K - 1.09x slower

- - -

Benchmarking ets_100000_10000...
Benchmarking map_100000_10000...

Name                       ips        average  deviation         median
map_100000_10000        232.37        4.30 ms    ±66.78%        3.48 ms
ets_100000_10000        149.05        6.71 ms    ±33.43%        5.88 ms

Comparison:
map_100000_10000        232.37
ets_100000_10000        149.05 - 1.56x slower

- - -

Benchmarking ets_1000000_100...
Benchmarking map_1000000_100...

Name                      ips        average  deviation         median
map_1000000_100       39.71 K       25.18 μs  ±4145.59%       15.00 μs
ets_1000000_100       36.51 K       27.39 μs   ±107.98%       23.00 μs

Comparison:
map_1000000_100       39.71 K
ets_1000000_100       36.51 K - 1.09x slower

- - -

Benchmarking ets_1000000_1000...
Benchmarking map_1000000_1000...

Name                       ips        average  deviation         median
map_1000000_1000        2.88 K      347.20 μs   ±953.55%      251.00 μs
ets_1000000_1000        2.42 K      413.69 μs    ±21.88%      401.00 μs

Comparison:
map_1000000_1000        2.88 K
ets_1000000_1000        2.42 K - 1.19x slower

- - -

Benchmarking ets_1000000_10000...
Benchmarking map_1000000_10000...

Name                        ips        average  deviation         median
map_1000000_10000        181.11        5.52 ms   ±218.75%        4.46 ms
ets_1000000_10000        138.43        7.22 ms    ±12.59%        7.09 ms

Comparison:
map_1000000_10000        181.11
ets_1000000_10000        138.43 - 1.31x slower

Most Liked

OvermindDL1

OvermindDL1

I’m actually quite impressed at just how fast ETS lookups are there. :slight_smile:

Where Next?

Popular in Discussions Top

PragTob
Hey everyone, this has been on my mind for some time and I’d love your input on it! TLDR: I feel like maps are superioer for storing and...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
MarioFlach
Hello, I want to share a project I’ve been working on for a while: https://github.com/almightycouch/gitgud Background Some time ago I ...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18584 126
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement