Skip to content

Commit 331ca47

Browse files
authored
Merge pull request #294 from ruby-go-gem/fix_bench
Add benchmark for Go sequential
2 parents 5fd40d5 + a2cad14 commit 331ca47

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

_benchmark/tarai.rb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,31 @@ def tarai(x, y, z) =
2828

2929
system("go version", exception: true)
3030

31+
MAX_BENCH_COUNT = 4
32+
3133
Benchmark.ips do |x|
32-
# sequential version
33-
x.report("sequential"){ 4.times{ tarai(14, 7, 0) } }
34+
# Ruby: sequential version
35+
x.report("Ruby: sequential"){ MAX_BENCH_COUNT.times{ tarai(14, 7, 0) } }
3436

35-
# parallel version (with Ractor)
36-
x.report("parallel (Ractor)"){
37-
4.times.map do
37+
# Ruby: parallel version (with Ractor)
38+
x.report("Ruby: Ractor"){
39+
MAX_BENCH_COUNT.times.map do
3840
Ractor.new { tarai(14, 7, 0) }
3941
end.each(&:take)
4042
}
4143

42-
# parallel version (with Fiber)
43-
x.report("parallel (Fiber)"){
44-
4.times.map do
44+
# Ruby: parallel version (with Fiber)
45+
x.report("Ruby: Fiber"){
46+
MAX_BENCH_COUNT.times.map do
4547
Fiber.new { tarai(14, 7, 0) }
4648
end.each(&:resume)
4749
}
4850

49-
# parallel version (with goroutine)
50-
x.report("parallel (goroutine)"){ Example::Benchmark.tarai_goroutine(14, 7, 0, 4) }
51+
# Go: sequential version
52+
x.report("Go: sequential"){ MAX_BENCH_COUNT.times{ Example::Benchmark.tarai(14, 7, 0) } }
53+
54+
# Go: parallel version (with goroutine)
55+
x.report("Go: goroutine"){ Example::Benchmark.tarai_goroutine(14, 7, 0, MAX_BENCH_COUNT) }
5156

5257
x.compare!
5358
end

0 commit comments

Comments
 (0)