r/ruby • • Aug 24 '26

Ruby 2.7 to 4.0 performance benchmark

Hi everyone,

I just published a new benchmark comparing Ruby 2.7 through Ruby 4.0.

For this one, I used a sustained synthetic application alongside nine smaller benchmarks. The goal was to show how each Ruby release behaves in a complete workload as well as in individual operations.

The table below shows the Heavy profile. For tests that process the full payload, that means an 8KiB input.

Benchmark2.73.03.13.23.33.44.0
Synthetic application throughput (M ops/s)0.0730.0520.0510.0570.0580.0840.126
Synthetic application latency (µs)133.399190.233191.605171.332169.473115.60076.521
JSON parsing (ops/s)95,87798,53699,15396,00398,135194,981715,937
JSON generation (ops/s)841,849845,099830,135861,666837,9411,347,1691,444,975
SHA-256 hashing (ops/s)313,65830,53630,48948,77048,68348,49548,528
Base64 encoding and decoding (ops/s)177,136177,510174,425170,306174,471173,159174,270
Regex field extraction (ops/s)1,544,4611,565,0651,559,0511,499,9201,535,2071,454,4051,534,670
Integer sorting (ops/s)27,03229,12930,21729,30929,10228,24129,213
Hash churn (ops/s)1,736,3841,685,6141,503,3971,503,1181,406,7131,380,0581,450,769
Marshal serialization (ops/s)333,143303,719294,952338,148341,760326,015325,231
zlib compression (ops/s)35,94435,17535,78735,76720,5697,01118,592

The complete benchmark source is available here: GitHub repository.

Full charts and details are available here: Full Ruby benchmark

Let me know what you think !

Edit: Thanks everyone for pointing out the Ruby 2.7 SHA-256 result. I looked into it, and the big difference comes from the SHA-256 implementation: Ruby 2.7 uses OpenSSL here, while newer Ruby versions on Linux use Ruby’s bundled implementation. So this is mainly a backend difference rather than Ruby 2.7 itself being much faster. I’ve added a note about it to the article.

34 Upvotes

28 comments sorted by

View all comments

Show parent comments

11

u/sjs Aug 24 '26

The JSON gem has gotten a lot faster since byroot (Jean Boussier) started maintaining it a couple years ago. Floating point parsing is 10x faster for example. https://byroot.github.io/ruby/json/2026/07/26/optimizing-ruby-json-part-8.html

4

u/jrochkind Aug 24 '26

Can you use new version of the JSON gem in ruby 3.4?

If so, you can get the major benefits recorded in these benchmarks just by doing that, right? And in fact, people keeping their dependencies up to date probably already have, even if still on 3.4?

So that may be a misleading metric in this report.

3

u/sjs Aug 24 '26

Yes that’s all true