Skip to content

Commit a2cad14

Browse files
committed
Extract to constant
1 parent 87cf37a commit a2cad14

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

_benchmark/tarai.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +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|
3234
# 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) } }
3436

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

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

4951
# 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) } }
5153

5254
# 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) }
5456

5557
x.compare!
5658
end

0 commit comments

Comments
 (0)