Skip to content

Commit e5fa570

Browse files
committed
Add benchmark with Fiber
1 parent 1f1d3e6 commit e5fa570

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

_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)