Skip to content

Commit d37d288

Browse files
authored
Merge pull request #202 from ruby-go-gem/fiber_benchmark
Add benchmark with Fiber
2 parents 1f1d3e6 + 62823f3 commit d37d288

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

_benchmark/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Benchmark
2-
## Ruby's [Ractor](https://docs.ruby-lang.org/en/master/ractor_md.html) vs Go's [goroutine](https://go.dev/tour/concurrency/1)
2+
## Ruby's [Ractor](https://docs.ruby-lang.org/en/master/ractor_md.html) vs Ruby's [Fiber](https://docs.ruby-lang.org/en/master/Fiber.html) vs Go's [goroutine](https://go.dev/tour/concurrency/1)
33
Benchmark with [tak function](https://en.wikipedia.org/wiki/Tak_(function)) [^tak]
44

55
[^tak]: https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/
@@ -11,14 +11,17 @@ ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [arm64-darwin23]
1111
Warming up --------------------------------------
1212
sequential 1.000 i/100ms
1313
parallel (Ractor) 1.000 i/100ms
14+
parallel (Fiber) 1.000 i/100ms
1415
parallel (goroutine) 1.000 i/100ms
1516
Calculating -------------------------------------
16-
sequential 0.019 (± 0.0%) i/s (51.42 s/i) - 1.000 in 51.417686s
17-
parallel (Ractor) 0.059 (± 0.0%) i/s (17.02 s/i) - 1.000 in 17.022087s
18-
parallel (goroutine) 1.677 (± 0.0%) i/s (596.20 ms/i) - 9.000 in 5.365863s
17+
sequential 0.017 (± 0.0%) i/s (57.84 s/i) - 1.000 in 57.844394s
18+
parallel (Ractor) 0.052 (± 0.0%) i/s (19.41 s/i) - 1.000 in 19.412980s
19+
parallel (Fiber) 0.018 (± 0.0%) i/s (56.78 s/i) - 1.000 in 56.780241s
20+
parallel (goroutine) 1.478 (± 0.0%) i/s (676.40 ms/i) - 8.000 in 5.412528s
1921

2022
Comparison:
21-
parallel (goroutine): 1.7 i/s
22-
parallel (Ractor): 0.1 i/s - 28.55x slower
23-
sequential: 0.0 i/s - 86.24x slower
23+
parallel (goroutine): 1.5 i/s
24+
parallel (Ractor): 0.1 i/s - 28.70x slower
25+
parallel (Fiber): 0.0 i/s - 83.95x slower
26+
sequential: 0.0 i/s - 85.52x slower
2427
```

_benchmark/tarai.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
end
77

88
require "benchmark/ips"
9+
require "fiber"
910

1011
# Build native extension before running benchmark
1112
Dir.chdir(File.join(__dir__, "..", "ruby", "testdata", "example")) do
@@ -38,6 +39,13 @@ def tarai(x, y, z) =
3839
end.each(&:take)
3940
}
4041

42+
# parallel version (with Fiber)
43+
x.report("parallel (Fiber)"){
44+
4.times.map do
45+
Fiber.new { tarai(14, 7, 0) }
46+
end.each(&:resume)
47+
}
48+
4149
# parallel version (with goroutine)
4250
x.report("parallel (goroutine)"){ Example::Benchmark.tarai_goroutine(14, 7, 0, 4) }
4351

0 commit comments

Comments
 (0)