Skip to content

Commit 1ac93fe

Browse files
committed
Add flat benchmark
1 parent 53e7a9a commit 1ac93fe

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/benchmark_new_futures.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22
require 'concurrent'
33
require 'concurrent-edge'
44

5+
# require 'ruby-prof'
6+
#
7+
# result = RubyProf.profile do
8+
# 1000.times do
9+
# head = Concurrent.future { 1 }
10+
# branch1 = head.then(&:succ)
11+
# branch2 = head.then(&:succ).then(&:succ)
12+
# branch3 = head.then(&:succ).then(&:succ).then(&:succ)
13+
# Concurrent.join(branch1, branch2, branch3).then { |(a, b, c)| a + b + c }.value!
14+
# end
15+
# end
16+
#
17+
# printer = RubyProf::FlatPrinter.new(result)
18+
# printer.print(STDOUT)
19+
#
20+
# printer = RubyProf::GraphPrinter.new(result)
21+
# printer.print(STDOUT, {})
22+
#
23+
# exit
24+
525
scale = 1
626
time = 10 * scale
727
warmup = 2 * scale
828
warmup *= 10 if Concurrent.on_jruby?
929

30+
Benchmark.ips(time, warmup) do |x|
31+
x.report('flat-old') { Concurrent::Promise.execute { 1 }.flat_map { |v| Concurrent::Promise.execute { v + 2 } }.value! }
32+
x.report('flat-new') { Concurrent.future(:fast) { 1 }.then { |v| Concurrent.future(:fast) { v+ 1 } }.flat.value! }
33+
x.compare!
34+
end
35+
1036
Benchmark.ips(time, warmup) do |x|
1137
x.report('status-old') { f = Concurrent::Promise.execute { nil }; 100.times { f.complete? } }
1238
x.report('status-new') { f = Concurrent.future(:fast) { nil }; 100.times { f.completed? } }

0 commit comments

Comments
 (0)