Skip to content

Commit 7b53868

Browse files
committed
Apply new Synchronization::Object capabilities to Edge::Future
1 parent d4011df commit 7b53868

File tree

2 files changed

+138
-112
lines changed

2 files changed

+138
-112
lines changed

examples/benchmark_new_futures.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'benchmark/ips'
2+
require 'concurrent'
3+
require 'concurrent-edge'
4+
5+
scale = 1
6+
time = 10 * scale
7+
warmup = 2 * scale
8+
warmup *= 10 if Concurrent.on_jruby?
9+
10+
11+
Benchmark.ips(time, warmup) do |x|
12+
of = Concurrent::Promise.execute { 1 }
13+
nf = Concurrent.future { 1 }
14+
x.report('value-old') { of.value! }
15+
x.report('value-new') { nf.value! }
16+
x.compare!
17+
end
18+
19+
20+
Benchmark.ips(time, warmup) do |x|
21+
ohead = Concurrent::Promise.execute { 1 }
22+
x.report('graph-old') do
23+
head = ohead
24+
branch1 = head.then(&:succ)
25+
branch2 = head.then(&:succ).then(&:succ)
26+
Concurrent::Promise.zip(branch1, branch2).then { |(a, b)| a + b }.value!
27+
end
28+
nhead = Concurrent.future { 1 }
29+
x.report('graph-new') do
30+
head = nhead
31+
branch1 = head.then(&:succ)
32+
branch2 = head.then(&:succ).then(&:succ)
33+
(branch1 + branch2).then { |(a, b)| a + b }.value!
34+
end
35+
x.compare!
36+
end
37+
38+
Benchmark.ips(time, warmup) do |x|
39+
x.report('immediate-old') { Concurrent::Promise.execute { nil }.value! }
40+
x.report('immediate-new') { Concurrent.future { nil }.value! }
41+
x.compare!
42+
end
43+
44+
Benchmark.ips(time, warmup) do |x|
45+
of = Concurrent::Promise.execute { 1 }
46+
nf = Concurrent.future { 1 }
47+
x.report('then-old') { of.then(&:succ).then(&:succ).value! }
48+
x.report('then-new') { nf.then(&:succ).then(&:succ).value! }
49+
x.compare!
50+
end
51+

0 commit comments

Comments
 (0)