@@ -28,29 +28,31 @@ def tarai(x, y, z) =
28
28
29
29
system ( "go version" , exception : true )
30
30
31
+ MAX_BENCH_COUNT = 4
32
+
31
33
Benchmark . ips do |x |
32
34
# Ruby: sequential version
33
- x . report ( "Ruby: sequential" ) { 4 . times { tarai ( 14 , 7 , 0 ) } }
35
+ x . report ( "Ruby: sequential" ) { MAX_BENCH_COUNT . times { tarai ( 14 , 7 , 0 ) } }
34
36
35
37
# Ruby: parallel version (with Ractor)
36
38
x . report ( "Ruby: Ractor" ) {
37
- 4 . times . map do
39
+ MAX_BENCH_COUNT . times . map do
38
40
Ractor . new { tarai ( 14 , 7 , 0 ) }
39
41
end . each ( &:take )
40
42
}
41
43
42
44
# Ruby: parallel version (with Fiber)
43
45
x . report ( "Ruby: Fiber" ) {
44
- 4 . times . map do
46
+ MAX_BENCH_COUNT . times . map do
45
47
Fiber . new { tarai ( 14 , 7 , 0 ) }
46
48
end . each ( &:resume )
47
49
}
48
50
49
51
# Go: sequential version
50
- x . report ( "Go: sequential" ) { 4 . times { Example ::Benchmark . tarai ( 14 , 7 , 0 ) } }
52
+ x . report ( "Go: sequential" ) { MAX_BENCH_COUNT . times { Example ::Benchmark . tarai ( 14 , 7 , 0 ) } }
51
53
52
54
# Go: parallel version (with goroutine)
53
- x . report ( "Go: goroutine" ) { Example ::Benchmark . tarai_goroutine ( 14 , 7 , 0 , 4 ) }
55
+ x . report ( "Go: goroutine" ) { Example ::Benchmark . tarai_goroutine ( 14 , 7 , 0 , MAX_BENCH_COUNT ) }
54
56
55
57
x . compare!
56
58
end
0 commit comments