1
0
Fork
You've already forked zig-ruby-extension
0
A native extension for Ruby written in Zig
  • Zig 77.2%
  • Ruby 22.8%
2025年11月14日 10:05:00 -06:00
ext/zig_rb Actually fix ZLS headers 2025年11月14日 10:05:00 -06:00
benchmark.rb Build Ruby extension with Zig 2022年12月22日 23:59:44 +01:00
Rakefile Build Ruby extension with Zig 2022年12月22日 23:59:44 +01:00
README.md Update for Zig 0.15.2 2025年11月09日 07:49:14 -06:00

What's this?

This repo contains an experiment of building a Ruby extension with Zig programming language. It implements a slightly altered version of 100 doors from Rosetta Code.

These are results of benchmarks on my machine (Thinkpad T14):

Warming up --------------------------------------
 Ruby 924.000 i/100ms
 Zig 13.885k i/100ms
Calculating -------------------------------------
 Ruby 12.745k (±22.1%) i/s - 60.984k in 5.052486s
 Zig 233.096k (± 0.1%) i/s - 1.166M in 5.003698s
Comparison:
 Zig: 233095.9 i/s
 Ruby: 12744.7 i/s - 18.29x (± 0.00) slower

However, if you edit extconf.rb to use -Drelease-fast flag, the difference is much bigger:

Warming up --------------------------------------
 Ruby 1.020k i/100ms
 Zig 171.828k i/100ms
Calculating -------------------------------------
 Ruby 10.289k (± 2.2%) i/s - 52.020k in 5.058112s
 Zig 2.833M (± 6.3%) i/s - 14.262M in 5.059011s
Comparison:
 Zig: 2833045.1 i/s
 Ruby: 10289.0 i/s - 275.35x (± 0.00) slower

Please note that this is only one benchmark, not much science behind it. It doesn't mean you will always get 270x speed boost on just rewriting in Zig.

How to run it

  1. Have Zig version 0.15.2 available on your system
  2. Clone this repo
  3. Run rake compile_ext
  4. Run rake benchmark