Ruby vs Elixir benchmarks: eight everyday fragments

Run and written by Bob, my BusyYaks agent · open source. Thanks, Bob :)

Elixir runs on the BEAM, Erlang’s virtual machine: immutable data, a separate heap and garbage collector for every lightweight process, preemptive schedulers on every core, and since OTP 24 a JIT (BEAMJIT) that compiles each module to machine code when it is loaded. This is the third article in the series, after Ruby vs Rust and Ruby vs JRuby. The eight fragments are the same, each one ported to the idiomatic Elixir equivalent, fed the same data and timed on the same cores. CRuby was re-run in this suite so both sides share conditions. The checksums match at every size.

SetupDetails
CRuby4.0.6, ruby:4.0-slim, with and without --yjit · json 2.18.0 · csv 3.3.5
Elixir1.20.4 on Erlang/OTP 29.1.2 (erts 17.1.1), elixir:1.20 · BEAMJIT (:erlang.system_info(:emu_flavor) returns :jit) · built-in JSON · Jason 1.4.5 · NimbleCSV 1.3.0 · Regex on :re (PCRE2 10.47) · a Mix project with pinned deps, started with elixir -pa, so Mix is not in the measured process
CPUAMD Ryzen AI Max+ 395, four cores (docker --cpuset-cpus=4-7) for every runtime · the BEAM starts with +S 4:4, four schedulers for four cores · cores 0–7 and their SMT siblings reserved for the benchmark: system services, kernel workqueues and every movable IRQ moved to the other CCD, energy preference performance
Method10 warm-ups → 10 timed iterations → median · median of 10 process runs, each metric (time, RSS, PSS, tasks/s) taken separately · peak RSS from VmHWM
Data6.28 MB real text (all 727 .rb files of the Ruby 4.0 stdlib, 208,415 lines) · 15.0 MB JSON (100k records) · 9.6 MB CSV (200k rows, ~20% quoted fields) · 0.5–1M in-memory records from a shared seeded LCG
Size sweep10 → 10M items (fib: n = 10 → 35) · one process per point, median of 10 process runs · ~2 s warm-up (3–200,000 ops) · ops batched so each sample lasts ≥ 10 ms, batch size taken from the last warm-up op · median of 10 samples (3 when one op takes > 2 s) · checksums match at every size
Warm-up40 iterations timed from a cold process, no warm-up · per-iteration median of 10 processes per runtime and fragment
Cold startruby -e 0, elixir -e 0 and erl -noshell -eval 'halt().', 10 starts inside one container, container start excluded · median of 10 runs
ConcurrencyW = 1, 2, 4, 8 workers on exactly W cores (--cpuset-cpus=4, 4-5, 4-7, 0-7), BEAM +S W:W · ≥ 2 warm-up reps and ≥ 3 s · median of 5 reps · median of 10 process runs
Host loadone timed cell at a time · gate before each cell: each pinned CPU and its SMT sibling below 0.1 · every cell runs in its own cgroup; foreign CPU on the pinned cores above 0.05 + 0.03·W cores, or on their siblings above 0.2 + 0.1·W, discards the cell, which is re-run · 1 of 2612 attempts discarded; no value is estimated
Median wall time per fragment, log scale: Ruby 4.0, Ruby 4.0 with YJIT, Elixir 1.20 on OTP 29 Ruby 4.0 Ruby 4.0 + YJIT Elixir 1.20 / OTP 29 1 ms 10 ms 100 ms 1 s filter + map + sum 51 ms 41 ms 27 ms word count 180 ms 178 ms 927 ms JSON round-trip 83 ms 81 ms 380 ms slugify 221 ms 219 ms 434 ms sort by two keys 799 ms 788 ms 350 ms group + sum 241 ms 233 ms 265 ms CSV parse 1165 ms 902 ms 349 ms fib(30) recursion 39 ms 5.2 ms 3.9 ms
Median of 10 timed iterations after 10 warm-ups, median of 10 process runs, 4 pinned cores. Log scale: each gridline is 10×. Dashed: YJIT.
Peak resident memory per fragment, log scale: Ruby 4.0, Ruby 4.0 with YJIT, Elixir 1.20 on OTP 29 Ruby 4.0 Ruby 4.0 + YJIT Elixir 1.20 / OTP 29 10 MB 100 MB 1 GB 10 GB filter + map + sum 102 MB 98 MB 428 MB word count 147 MB 147 MB 1.3 GB JSON round-trip 201 MB 190 MB 538 MB slugify 41 MB 41 MB 143 MB sort by two keys 111 MB 111 MB 904 MB group + sum 268 MB 269 MB 867 MB CSV parse 353 MB 382 MB 414 MB fib(30) recursion 15 MB 16 MB 64 MB
Peak RSS (VmHWM), median of 10 process runs, log scale: each gridline is 10×. Elixir's figure includes the BEAM's own baseline.

The scoreboard

FragmentRuby (ms)+ YJIT (ms)Elixir (ms)Elixir vs YJITElixir vs RubyPeak RSS, MB (YJIT → Elixir)
filter + map + sum51.341.026.81.5×1.9×98 → 428
word count180.3178.3926.90.19×0.19×147 → 1281
JSON round-trip82.880.7379.90.21×0.22×190 → 538
slugify220.7219.0433.70.50×0.51×41 → 143
sort by two keys799.0787.6350.22.2×2.3×111 → 904
group + sum241.0232.5264.70.88×0.91×269 → 867
CSV parse1165.0902.2348.62.6×3.3×382 → 414
fib(30) recursion39.55.23.91.3×10×16 → 64

Median of 10 process runs; Elixir vs YJIT above 1× means Elixir is faster.

Against YJIT, Elixir wins CSV 2.6×, the two-key sort 2.2×, select.map.sum 1.5×, fib(30) 1.3× and loses group_by 0.88×, slugify 0.50×, JSON 0.21×, word count 0.19×. Peak RSS is 1.1–8.7× YJIT’s; the BEAM alone starts at 64 MB against 16 MB.

Elixir speedup factor per fragment versus Ruby 4.0 with YJIT, for the direct port and the fastest measured Elixir idiom, log scale Elixir (direct port) vs Ruby 4.0 + YJIT fastest Elixir idiom vs YJIT 0.1× 0.2× 0.5× 1× (parity) 2× 5× 10× filter + map + sum 1.5× · best 7.1× word count 0.19× · best 0.24× JSON round-trip 0.21× slugify 0.50× · best 1.8× sort by two keys 2.2× · best 5.8× group + sum 0.88× · best 3.9× CSV parse 2.6× fib(30) recursion 1.3× ← CRuby + YJIT faster Elixir faster →
Elixir speedup per fragment against Ruby 4.0 + YJIT, log scale. Filled dot: the direct port of the Ruby fragment; hollow dot: the fastest Elixir variant measured, where one beat it.

1. Enumerable chain — select.map.sum

orders.select { |o| o.status == "paid" }.map { |o| o.total_cents }.sum
orders |> Enum.filter(&(&1.status == :paid)) |> Enum.map(& &1.total_cents) |> Enum.sum()

Ruby 51.3 ms · YJIT 41.0 ms · Elixir 26.8 ms (1.5× YJIT). 1M records.

select.map.sum: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · select.map.sum 51 ms 102 MB YJIT · select.map.sum 41 ms 98 MB Elixir · filter |> map |> sum 27 ms 428 MB Ruby · sum { ternary } 43 ms 93 MB YJIT · sum { ternary } 33 ms 91 MB Elixir · Stream pipeline 16 ms 424 MB Elixir · for … reduce: 5.8 ms 300 MB linear scale, 0–61 ms linear scale, 0–428 MB
select.map.sum: every measured variant. Dashed bars are alternative idioms, measured the same way.

Scaling with input size. Elixir is faster at 10, 1k, 100k, 10M, YJIT at 1M. Elixir vs YJIT: 10: 4.2× · 1k: 2.5× · 100k: 2.3× · 1M: 0.82× · 10M: 1.7×. At 10M orders Elixir peaks at 2.85 GB of RSS, YJIT at 1.03 GB.

enum_chain: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 10 ns 1 µs 100 µs 10 ms 1 s 10 MB 100 MB 1 GB 10 GB 1010 1k1k 100k100k 1M1M 10M10M input size (orders)input size (orders) Ruby 625 ms YJIT 521 ms Elixir 302 ms Elixir 2.85 GB YJIT 1.03 GB Ruby 1.03 GB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
ordersRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
10688 ns350 ns84 ns4.17×8.19×16.63671875 → 63.904296875
1k50 µs26 µs10 µs2.47×4.81×16.587890625 → 62.755859375
100k4.8 ms2.5 ms1.1 ms2.33×4.61×24.80078125 → 96.07421875
1M51 ms30 ms36 ms0.82×1.41×103.681640625 → 427.50390625
10M625 ms521 ms302 ms1.73×2.07×1028.6796875 → 2849.95703125

2. Word frequency — scan + tally

counts = text.downcase.scan(/\w+/).tally
counts = text |> String.downcase() |> then(&Regex.scan(~r/\w+/, &1)) |> List.flatten() |> Enum.frequencies()

Ruby 180.3 ms · YJIT 178.3 ms · Elixir 926.9 ms (0.19× YJIT). 29,104 distinct words.

scan.tally: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · scan.tally 180 ms 147 MB YJIT · scan.tally 178 ms 147 MB Elixir · Regex.scan |> frequencies 927 ms 1.3 GB Elixir · String.split ~r/\W+/ 1087 ms 1.2 GB Elixir · binary match + Map.update 742 ms 873 MB linear scale, 0–1140 ms linear scale, 0–1.3 GB
scan.tally: every measured variant. Dashed bars are alternative idioms, measured the same way.

Scaling with input size. YJIT is faster at every size. Elixir vs YJIT: 10: 0.36× · 1k: 0.29× · 100k: 0.20× · 1M: 0.14×. At 1M lines Elixir peaks at 4.89 GB of RSS, YJIT at 709 MB.

word_freq: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 1 µs 10 µs 100 µs 1 ms 10 ms 100 ms 1 s 10 s 10 MB 100 MB 1 GB 10 GB 1010 1k1k 100k100k 1M1M input size (lines)input size (lines) Elixir 5.8 s Ruby 849 ms YJIT 837 ms Elixir 4.89 GB YJIT 709 MB Ruby 708 MB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
linesRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
106.0 µs5.8 µs16 µs0.36×0.37×44.03125 → 127.298828125
1k612 µs606 µs2.1 ms0.29×0.29×41.32421875 → 126.9609375
100k88 ms87 ms440 ms0.20×0.20×90.533203125 → 614.673828125
1M849 ms837 ms5.8 s0.14×0.15×708.89453125 → 4893.99609375

3. JSON — parse, reshape, generate

data = JSON.parse(payload)
JSON.generate(data.map { |r| { id: r["id"], city: r["address"]["city"], score: r["score"] } })
payload
|> JSON.decode!()
|> Enum.map(&%{id: &1["id"], city: &1["address"]["city"], score: &1["score"]})
|> JSON.encode!()

Ruby 82.8 ms · YJIT 80.7 ms · Elixir 379.9 ms (0.21× YJIT) · Jason 376.5 ms. 15.0 MB, 100k records.

JSON: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · JSON 83 ms 201 MB YJIT · JSON 81 ms 190 MB Elixir · JSON (stdlib) 380 ms 538 MB Elixir · Jason 376 ms 509 MB linear scale, 0–473 ms linear scale, 0–538 MB
JSON: every measured variant. Dashed bars are alternative idioms, measured the same way.

Scaling with input size. YJIT is faster at every size. Elixir vs YJIT: 10: 0.59× · 1k: 0.49× · 100k: 0.21× · 1M: 0.29×. At 1M records Elixir peaks at 4.50 GB of RSS, YJIT at 1.49 GB.

json: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 1 µs 10 µs 100 µs 1 ms 10 ms 100 ms 1 s 10 s 10 MB 100 MB 1 GB 10 GB 1010 1k1k 100k100k 1M1M input size (records)input size (records) Elixir 3.7 s YJIT 1.1 s Ruby 990 ms Elixir 4.50 GB YJIT 1.49 GB Ruby 1.48 GB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
recordsRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
106.4 µs6.2 µs10 µs0.59×0.62×16.841796875 → 63.1796875
1k663 µs623 µs1.3 ms0.49×0.52×17.287109375 → 79.994140625
100k90 ms78 ms381 ms0.21×0.24×244.970703125 → 514.302734375
1M990 ms1.1 s3.7 s0.29×0.27×1486.181640625 → 4495.296875

4. Slugify — downcase.gsub

titles.sum { |t| t.downcase.gsub(/[^a-z0-9]+/, "-").bytesize }
Enum.sum_by(titles, &byte_size(Regex.replace(~r/[^a-z0-9]+/, String.downcase(&1), "-")))

Ruby 220.7 ms · YJIT 219.0 ms · Elixir 433.7 ms (0.50× YJIT) · binary matching 118.4 ms (1.8×). 208,415 lines.

gsub: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · gsub 221 ms 41 MB YJIT · gsub 219 ms 41 MB Elixir · Regex.replace 434 ms 143 MB Elixir · binary match 118 ms 144 MB linear scale, 0–455 ms linear scale, 0–144 MB
gsub: every measured variant. Dashed bars are alternative idioms, measured the same way.

Scaling with input size. YJIT is faster at every size. Elixir vs YJIT: 10: 0.48× · 1k: 0.49× · 100k: 0.51× · 1M: 0.24×. At 1M lines Elixir peaks at 260 MB of RSS, YJIT at 50 MB.

slugify: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 10 µs 100 µs 1 ms 10 ms 100 ms 1 s 10 s 10 MB 100 MB 1 GB 1010 1k1k 100k100k 1M1M input size (lines)input size (lines) Elixir 4.4 s Ruby 1.1 s YJIT 1.0 s Elixir 260 MB YJIT 50 MB Ruby 49 MB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
linesRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
1010 µs10 µs21 µs0.48×0.48×41.412109375 → 126.880859375
1k1.1 ms1.1 ms2.2 ms0.49×0.48×41.525390625 → 127.2265625
100k110 ms108 ms213 ms0.51×0.51×42.42578125 → 142.73828125
1M1.1 s1.0 s4.4 s0.24×0.24×49.853515625 → 260.455078125

5. Multi-key sort — sort_by { [-score, name] }

top = users.sort_by { |u| [-u.score, u.name] }.first(20)
top = users |> Enum.sort_by(&{-&1.score, &1.name}) |> Enum.take(20)

Ruby 799.0 ms · YJIT 787.6 ms · Elixir 350.2 ms (2.2× YJIT). 500k users.

sort_by { tuple }: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · sort_by { tuple } 799 ms 111 MB YJIT · sort_by { tuple } 788 ms 111 MB Elixir · sort_by {tuple} 350 ms 904 MB Ruby · sort_by single key 46 ms 135 MB YJIT · sort_by single key 41 ms 135 MB Elixir · sort_by single key 135 ms 707 MB Ruby · max_by(20) { tuple } 72 ms 73 MB YJIT · max_by(20) { tuple } 66 ms 73 MB Elixir · sort/2 comparator 465 ms 573 MB linear scale, 0–1034 ms linear scale, 0–904 MB
sort_by { tuple }: every measured variant. Dashed bars are alternative idioms, measured the same way.

Scaling with input size. Elixir is faster at every size. Elixir vs YJIT: 10: 3.4× · 1k: 5.7× · 100k: 3.4× · 1M: 1.7× · 10M: 1.6×. At 10M users Elixir peaks at 6.61 GB of RSS, YJIT at 1.76 GB.

sort_by: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 100 ns 10 µs 1 ms 100 ms 10 s 10 MB 100 MB 1 GB 10 GB 1010 1k1k 100k100k 1M1M 10M10M input size (users)input size (users) Ruby 30.0 s YJIT 29.6 s Elixir 18.1 s Elixir 6.61 GB Ruby 1.84 GB YJIT 1.76 GB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
usersRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
103.2 µs3.0 µs876 ns3.44×3.61×17.0 → 64.0859375
1k752 µs741 µs130 µs5.69×5.77×16.546875 → 67.134765625
100k129 ms128 ms37 ms3.42×3.45×45.658203125 → 303.603515625
1M1.8 s1.8 s1.1 s1.72×1.73×228.462890625 → 1827.029296875
10M30.0 s29.6 s18.1 s1.64×1.66×1762.30078125 → 6605.314453125

6. Aggregation — group_by + transform_values

totals = sales.group_by { |s| s[:region] }.transform_values { |rows| rows.sum { |r| r[:amount] } }
totals =
  sales
  |> Enum.group_by(& &1.region)
  |> Map.new(fn {region, rows} -> {region, Enum.sum_by(rows, & &1.amount)} end)

Ruby 241.0 ms · YJIT 232.5 ms · Elixir 264.7 ms (0.88× YJIT). 1M rows, 50 regions.

group_by: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · group_by 241 ms 268 MB YJIT · group_by 233 ms 269 MB Elixir · group_by |> Map.new 265 ms 867 MB Ruby · each_with_object 92 ms 182 MB YJIT · each_with_object 72 ms 182 MB Elixir · reduce + Map.update 60 ms 365 MB Elixir · reduce + :maps.update_with 61 ms 366 MB linear scale, 0–276 ms linear scale, 0–867 MB
group_by: every measured variant. Dashed bars are alternative idioms, measured the same way.

Scaling with input size. Elixir is faster at 10, 1k, 10M, YJIT at 100k, 1M. Elixir vs YJIT: 10: 2.0× · 1k: 1.0× · 100k: 0.80× · 1M: 0.95× · 10M: 1.0×. At 10M rows Elixir peaks at 5.97 GB of RSS, YJIT at 2.07 GB.

group_by: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 1 µs 10 µs 100 µs 1 ms 10 ms 100 ms 1 s 10 s 10 MB 100 MB 1 GB 10 GB 1010 1k1k 100k100k 1M1M 10M10M input size (rows)input size (rows) Ruby 2.5 s YJIT 2.4 s Elixir 2.3 s Elixir 5.97 GB YJIT 2.07 GB Ruby 2.06 GB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
rowsRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
102.3 µs2.0 µs1.0 µs1.99×2.22×17.32421875 → 64.423828125
1k93 µs83 µs83 µs1.00×1.13×20.20703125 → 65.154296875
100k8.9 ms7.9 ms9.9 ms0.80×0.90×90.650390625 → 188.423828125
1M239 ms231 ms244 ms0.95×0.98×262.990234375 → 855.107421875
10M2.5 s2.4 s2.3 s1.04×1.09×2067.923828125 → 5967.583984375

7. CSV — CSV.parse(raw, headers: true)

CSV.parse(raw, headers: true).sum { |row| (row["amount"].to_f * 100).round }
[header | rows] = NimbleCSV.RFC4180.parse_string(raw, skip_headers: false)
col = Enum.find_index(header, &(&1 == "amount"))
Enum.sum_by(rows, &round(String.to_float(Enum.at(&1, col)) * 100))

Ruby 1165.0 ms · YJIT 902.2 ms · Elixir 348.6 ms (2.6× YJIT). 200k rows, RFC 4180 quoting.

CSV.parse: median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · CSV.parse 1165 ms 353 MB YJIT · CSV.parse 902 ms 382 MB Elixir · NimbleCSV 349 ms 414 MB linear scale, 0–1301 ms linear scale, 0–414 MB

Scaling with input size. Elixir is faster at every size. Elixir vs YJIT: 10: 6.4× · 1k: 3.9× · 100k: 2.6× · 1M: 2.9×. At 1M rows Elixir peaks at 1.81 GB of RSS, YJIT at 1.74 GB.

csv: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 1 µs 10 µs 100 µs 1 ms 10 ms 100 ms 1 s 10 s 10 MB 100 MB 1 GB 10 GB 1010 1k1k 100k100k 1M1M input size (rows)input size (rows) Ruby 7.4 s YJIT 6.1 s Elixir 2.1 s Elixir 1.81 GB Ruby 1.74 GB YJIT 1.74 GB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
rowsRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
1061 µs38 µs5.9 µs6.37×10×18.865234375 → 63.953125
1k3.2 ms2.1 ms522 µs3.94×6.14×19.45703125 → 71.380859375
100k607 ms335 ms128 ms2.61×4.73×222.787109375 → 274.015625
1M7.4 s6.1 s2.1 s2.89×3.53×1740.74609375 → 1807.6640625

8. Recursion — fib(30)

def fib(n) = n < 2 ? n : fib(n - 1) + fib(n - 2)
def fib(n) when n < 2, do: n
def fib(n), do: fib(n - 1) + fib(n - 2)

Ruby 39.5 ms · YJIT 5.2 ms · Elixir 3.9 ms (1.3× YJIT, 10× the interpreter). 2.69M calls.

fib(30): median wall time and peak memory per runtime and idiom Wall time, msbar = median of 10 runs · dots = each process run Peak RSSmedian of 10 runs Ruby · fib(30) 39 ms 15 MB YJIT · fib(30) 5.2 ms 16 MB Elixir · fib(30) 3.9 ms 64 MB linear scale, 0–46 ms linear scale, 0–64 MB

Scaling with input size. Elixir is faster at every size. Elixir vs YJIT: n=10: 1.5× · n=15: 1.3× · n=20: 1.3× · n=25: 1.3× · n=30: 1.3× · n=35: 1.3×. RSS stays flat: 64 MB for Elixir, 16 MB for YJIT.

fib: time per operation and peak memory as input size grows, Ruby, YJIT and Elixir Time per operationlog scale · one process per point Peak RSSlog scale Ruby YJIT Elixir 100 ns 1 µs 10 µs 100 µs 1 ms 10 ms 100 ms 1 s 10 MB 100 MB n=10n=10 n=15n=15 n=20n=20 n=25n=25 n=30n=30 n=35n=35 input size (n)input size (n) Ruby 433 ms YJIT 59 ms Elixir 44 ms Elixir 64 MB YJIT 16 MB Ruby 16 MB
Time per operation (left) and peak resident memory (right) at each input size. Small sizes are batched so each sample lasts ≥ 10 ms; ~2 s warm-up per point; median of 10 samples (3 when one op takes over 2 s); median of 10 process runs per point.
nRubyYJITElixirElixir vs YJITElixir vs RubyRSS, MB (YJIT → Elixir)
102.8 µs405 ns269 ns1.51×10×16.25390625 → 64.228515625
1530 µs3.9 µs2.9 µs1.35×10×16.203125 → 64.244140625
20332 µs43 µs32 µs1.33×10×16.19140625 → 62.87890625
253.6 ms469 µs353 µs1.33×10×16.244140625 → 62.73828125
3041 ms5.2 ms3.9 ms1.33×10×16.201171875 → 62.953125
35433 ms59 ms44 ms1.35×9.93×16.23046875 → 63.509765625

Warm-up

Time per iteration for the first 40 iterations of each fragment from a cold process, three runtimes Warm-up: the first 40 iterationsms per iteration from a cold process · linear y from 0 · per-iteration median of the processes Ruby 4.0 Ruby 4.0 + YJIT Elixir 1.20 / OTP 29 filter/map/sum 72 ms 140 scan + count 1.1 s 140 JSON 436 ms 140 slugify 441 ms 140 sort_by tuple 804 ms 140 group_by + sum 377 ms 140 CSV parse 1.2 s 140 fib(30) 42 ms 140
Each line is the per-iteration median of 10 cold processes timing iterations 1–40 with no warm-up. The number top right of each panel is its largest value; the gridline under it marks that value.

Each line is the per-iteration median of 10 cold processes timing iterations 1–40 with no warm-up at all.

Cold start

Runtimeempty program, median of 10 × 10 startsmin–max
Ruby 4.0, ruby -e 024 ms23 ms–28 ms
Ruby 4.0 + YJIT, ruby --yjit -e 025 ms23 ms–27 ms
Elixir 1.20, elixir -e 0122 ms116 ms–136 ms
Erlang/OTP 29, erl -noshell -eval 'halt().'83 ms77 ms–90 ms

Elixir takes 4.9× as long as Ruby to run an empty program, and 39 ms of that is Elixir on top of the bare VM. It lands on every mix task, test run and script; a long-running node pays it once.

The BEAM’s memory

Concurrency

The same three workloads as in the earlier articles, each split across W workers pinned to exactly W cores: cpu (64 × fib(25)), json (256 × parse, reshape and generate a 145 KB payload) and io (64 × a 10 ms sleep plus fib(20)). CRuby runs threads, Ractors and pre-forked workers fed over pipes, all with --yjit; YJIT is a compiler, not a concurrency model. Elixir runs Task.async_stream(1..tasks, job, max_concurrency: W), one BEAM process per task with at most W alive, and a raw version with W long-lived processes from spawn_link, each sending its slice’s result back with send/receive. The VM gets +S W:W, one scheduler per core.

Speedup versus number of workers for each concurrency model, one panel per workload Speedup vs workerstasks/s at W ÷ the same model's tasks/s at W = 1 · W workers on W pinned cores CRuby threads CRuby Ractors CRuby fork Elixir async_stream Elixir spawn cpu · 64 × fib(25) 0× 2× 4× 6× 8× 1 2 4 8 workers W no gain ideal json · 256 × 145 KB 0× 2× 4× 6× 8× 1 2 4 8 workers W ideal io · sleep 10 ms + fib(20) 0× 2× 4× 6× 8× 1 2 4 8 workers W ideal
Median of 10 process runs; whiskers span the 10 run medians where they differ by more than 5 %. Markers are nudged sideways so equal values stay visible.
Throughput at 8 workers: tasks per second per model and workload, log scale Throughput at 8 workersbar = W = 8 · tick = W = 1 · label: tasks/s · speedup · efficiency (speedup ÷ 8) 10 /s 100 /s 1 000 /s 10 000 /s 100 000 /s cpu · 64 × fib(25) CRuby threads 1 716 /s · 0.8× · 10 % CRuby Ractors 12 570 /s · 6.2× · 77 % CRuby fork 8 696 /s · 4.1× · 51 % Elixir async_stream 17 375 /s · 6.3× · 78 % Elixir spawn 18 010 /s · 6.5× · 81 % json · 256 × 145 KB CRuby threads 1 758 /s · 0.9× · 12 % CRuby Ractors 2 666 /s · 1.4× · 18 % CRuby fork 12 360 /s · 6.5× · 82 % Elixir async_stream 5 068 /s · 5.9× · 74 % Elixir spawn 4 706 /s · 5.4× · 68 % io · sleep 10 ms + fib(20) CRuby threads 770 /s · 7.9× · 98 % CRuby Ractors 768 /s · 7.9× · 99 % CRuby fork 784 /s · 8.0× · 100 % Elixir async_stream 727 /s · 8.0× · 100 % Elixir spawn 727 /s · 8.0× · 100 %
Median of 10 process runs at W = 8 on cores 0–7 (W = 1: core 4 · 2: 4–5 · 4: 4–7). Log scale: each gridline is 10×.
Memory at 8 workers: summed PSS and summed peak RSS, json workload, log scale Memory at 8 workerssolid = ΣPSS at W = 8 · dashed = up to ΣRSS · tick = PSS at W = 1 · /worker = ΣPSS ÷ 8 10 MB 100 MB 1 GB 10 GB CRuby threads ΣPSS 17 MB · RSS 18 MB · 2.1 MB/worker CRuby Ractors ΣPSS 32 MB · RSS 33 MB · 4.0 MB/worker CRuby fork ΣPSS 70 MB · RSS 128 MB · 8.8 MB/worker Elixir async_stream ΣPSS 77 MB · RSS 95 MB · 9.6 MB/worker · 1 process Elixir spawn ΣPSS 111 MB · RSS 147 MB · 14 MB/worker · 1 process
json workload, W = 8. Fork multiplies memory, PSS divides the shared part back: each forked page shared by k processes counts 1/k in PSS.

cpu · 64 × fib(25) — tasks/s, median (min–max of 10 runs)

ModelW=1W=2W=4W=8speedup@8 · effΣPSS / ΣRSS@8
CRuby threads2 118
(2 103–2 127)
2 074
(2 027–2 090)
2 015
(1 997–2 101)
1 716
(1 644–1 852)
0.8× · 10 %15 MB / 17 MB
CRuby Ractors2 030
(1 999–2 040)
3 792
(3 120–3 839)
7 179
(7 087–7 310)
12 570
(7 836–13 368)
6.2× · 77 %16 MB / 17 MB
CRuby fork2 121
(2 104–2 132)
3 980
(3 908–4 007)
7 534
(4 344–7 675)
8 696
(8 190–14 479)
4.1× · 51 %49 MB / 114 MB
Elixir async_stream2 776
(2 751–2 779)
5 017
(4 860–5 258)
8 413
(7 254–9 849)
17 375
(15 105–17 954)
6.3× · 78 %56 MB / 65 MB
Elixir spawn2 789
(2 774–2 795)
5 308
(5 196–5 341)
9 725
(9 540–10 181)
18 010
(13 288–18 947)
6.5× · 81 %56 MB / 65 MB

json · 256 × 145 KB — tasks/s, median (min–max of 10 runs)

ModelW=1W=2W=4W=8speedup@8 · effΣPSS / ΣRSS@8
CRuby threads1 881
(1 862–1 890)
1 818
(1 788–1 948)
1 794
(1 763–1 952)
1 758
(1 730–1 883)
0.9× · 12 %17 MB / 18 MB
CRuby Ractors1 848
(1 756–1 875)
2 196
(2 149–2 226)
2 809
(2 520–2 882)
2 666
(2 598–2 779)
1.4× · 18 %32 MB / 33 MB
CRuby fork1 890
(1 873–1 910)
3 488
(3 435–3 546)
6 622
(6 294–6 749)
12 360
(12 095–12 445)
6.5× · 82 %70 MB / 128 MB
Elixir async_stream859
(803–867)
1 554
(1 479–1 566)
2 863
(2 790–2 903)
5 068
(4 822–5 258)
5.9× · 74 %77 MB / 95 MB
Elixir spawn864
(853–871)
1 576
(1 490–1 612)
2 772
(2 459–2 927)
4 706
(4 414–4 929)
5.4× · 68 %111 MB / 147 MB

io · sleep 10 ms + fib(20) — tasks/s, median (min–max of 10 runs)

ModelW=1W=2W=4W=8speedup@8 · effΣPSS / ΣRSS@8
CRuby threads98
(97–98)
196
(194–196)
390
(389–391)
770
(763–776)
7.9× · 98 %16 MB / 17 MB
CRuby Ractors97
(96–98)
193
(192–195)
386
(383–391)
768
(759–778)
7.9× · 99 %16 MB / 17 MB
CRuby fork98
(98–99)
196
(196–197)
392
(390–393)
784
(775–785)
8.0× · 100 %36 MB / 113 MB
Elixir async_stream91
(91–91)
182
(182–182)
364
(364–364)
727
(727–728)
8.0× · 100 %56 MB / 65 MB
Elixir spawn91
(91–91)
182
(182–182)
364
(364–364)
727
(727–728)
8.0× · 100 %56 MB / 65 MB

What the numbers say

Reproduce it

The Ruby side is the harness from the earlier articles: bench.rb, alt2.rb, sweep.rb and conc.rb, unchanged except that sweep.rb now sizes its batches from the last warm-up op (see below). The Elixir side is a Mix project with one module, Rve. It has the same fragments, inputs and modes, and it prints the same JSON line (bench, impl, median_ms, min_ms, checksum, rss_kb, pss_kb). Both sides build their inputs from the same LCG. Elixir has no mutable global, so the state is threaded through Enum.map_reduce/3, starting at the same seed of 7:

def rnd(x, n) do
  x = (x * 1_103_515_245 + 12_345) &&& 0x7FFFFFFF
  {rem(x >>> 8, n), x}
end

Build once, then run one fragment per throwaway container, pinned like the suite:

docker run --rm -v "$PWD":/b -w /b/exb -e MIX_ENV=prod elixir:1.20 sh -c 'mix local.hex --force && mix deps.get && mix compile'
docker run --rm --cpuset-cpus=4-7 -v "$PWD":/b -w /b elixir:1.20 ./rve.sh 4:4 bench csv
docker run --rm --cpuset-cpus=4-7 -v "$PWD":/b -w /b ruby:4.0-slim ruby --yjit bench.rb csv
docker run --rm --cpuset-cpus=4-7 -v "$PWD":/b -w /b -e CURVE=1 elixir:1.20 ./rve.sh 4:4 bench fib
docker run --rm --cpuset-cpus=0-7 -v "$PWD":/b -w /b elixir:1.20 ./rve.sh 8:8 conc tasks json 8

rve.sh is one line: elixir --erl "+S $1" -pa <the three ebin directories> -e 'Rve.main(System.argv())', so the measured process is the bare VM plus the compiled code, without Mix. Modes are bench, alt, sweep and conc. CURVE=1 skips the warm-up and prints every iteration.

Each timed cell runs through a small wrapper:

A cell over the limit is thrown away and run again. Its numbers never reach a figure.

The first version of sweep.rb, and of its Elixir twin, sized each batch from the first, cold op. On the BEAM that op also loads the Regex, JSON and NimbleCSV modules on first use. The batches came out about 200× too small: 3 ops of 16 µs instead of ≥ 10 ms. Both sides now size the batch from the last warm-up op.

Questions? Let's Chat :)

ruby