Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions _benchmark/tarai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,31 @@ def tarai(x, y, z) =

system("go version", exception: true)

MAX_BENCH_COUNT = 4

Benchmark.ips do |x|
# sequential version
x.report("sequential"){ 4.times{ tarai(14, 7, 0) } }
# Ruby: sequential version
x.report("Ruby: sequential"){ MAX_BENCH_COUNT.times{ tarai(14, 7, 0) } }

# parallel version (with Ractor)
x.report("parallel (Ractor)"){
4.times.map do
# Ruby: parallel version (with Ractor)
x.report("Ruby: Ractor"){
MAX_BENCH_COUNT.times.map do
Ractor.new { tarai(14, 7, 0) }
end.each(&:take)
}

# parallel version (with Fiber)
x.report("parallel (Fiber)"){
4.times.map do
# Ruby: parallel version (with Fiber)
x.report("Ruby: Fiber"){
MAX_BENCH_COUNT.times.map do
Fiber.new { tarai(14, 7, 0) }
end.each(&:resume)
}

# parallel version (with goroutine)
x.report("parallel (goroutine)"){ Example::Benchmark.tarai_goroutine(14, 7, 0, 4) }
# Go: sequential version
x.report("Go: sequential"){ MAX_BENCH_COUNT.times{ Example::Benchmark.tarai(14, 7, 0) } }

# Go: parallel version (with goroutine)
x.report("Go: goroutine"){ Example::Benchmark.tarai_goroutine(14, 7, 0, MAX_BENCH_COUNT) }

x.compare!
end