@@ -28,26 +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
- # 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 ) } }
34
36
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
38
40
Ractor . new { tarai ( 14 , 7 , 0 ) }
39
41
end . each ( &:take )
40
42
}
41
43
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
45
47
Fiber . new { tarai ( 14 , 7 , 0 ) }
46
48
end . each ( &:resume )
47
49
}
48
50
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 ) }
51
56
52
57
x . compare!
53
58
end
0 commit comments