Skip to content

Commit 9167ddb

Browse files
committed
Merge pull request #448 from ruby-concurrency/compare-async-implementations
[SPIKE] Improved Async implementation
2 parents 26b7a77 + 5475c90 commit 9167ddb

File tree

3 files changed

+217
-71
lines changed

3 files changed

+217
-71
lines changed

examples/benchmark_async.rb

Lines changed: 131 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def foo(latch = nil)
2424

2525
IPS_NUM = 100
2626
BMBM_NUM = 100_000
27+
SMALL_BMBM = 250
28+
29+
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
30+
puts "Long-lived objects"
31+
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
32+
puts ""
2733

2834
Benchmark.ips do |bm|
2935
celluloid = CelluloidClass.new
@@ -59,68 +65,163 @@ def foo(latch = nil)
5965
end
6066
end
6167

68+
puts ""
69+
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
70+
puts "Short-lived objects"
71+
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
72+
puts ""
73+
74+
Benchmark.ips do |bm|
75+
bm.report('future') do
76+
latch = Concurrent::CountDownLatch.new(IPS_NUM)
77+
IPS_NUM.times do
78+
Concurrent::Future.execute { latch.count_down }
79+
end
80+
latch.wait
81+
end
82+
83+
async = AsyncClass.new
84+
bm.report('async') do
85+
latch = Concurrent::CountDownLatch.new(IPS_NUM)
86+
IPS_NUM.times { AsyncClass.new.async.foo(latch) }
87+
latch.wait
88+
end
89+
90+
bm.compare!
91+
end
92+
93+
Benchmark.bmbm do |bm|
94+
bm.report('celluloid') do
95+
latch = Concurrent::CountDownLatch.new(SMALL_BMBM)
96+
SMALL_BMBM.times { CelluloidClass.new.async.foo(latch) }
97+
latch.wait
98+
end
99+
100+
bm.report('async') do
101+
latch = Concurrent::CountDownLatch.new(SMALL_BMBM)
102+
SMALL_BMBM.times { AsyncClass.new.async.foo(latch) }
103+
latch.wait
104+
end
105+
end
106+
62107
__END__
63108

64109
===========================================================
65-
Async Benchmarks
110+
Async Benchmarks
66111
===========================================================
67112

68-
Computer:
113+
Computer:
69114

70-
* OS X Yosemite
71-
- Version 10.10.4
115+
* OS X Yosemite
116+
- Version 10.10.4
72117
* MacBook Pro
73-
- Retina, 13-inch, Early 2015
118+
- Retina, 13-inch, Early 2015
74119
* Processor 3.1 GHz Intel Core i7
75120
* Memory 16 GB 1867 MHz DDR3
76121
* Physical Volumes:
77122
- Apple SSD SM0512G
78-
- 500 GB
123+
- 500 GB
79124

80125
===========================================================
81-
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
126+
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
82127
===========================================================
83128

129+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130+
Long-lived objects
131+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132+
133+
Calculating -------------------------------------
134+
celluloid 22.000 i/100ms
135+
async 37.000 i/100ms
136+
-------------------------------------------------
137+
celluloid 239.639 (±10.8%) i/s - 1.188k
138+
async 374.885 (± 2.7%) i/s - 1.887k
139+
140+
Comparison:
141+
async: 374.9 i/s
142+
celluloid: 239.6 i/s - 1.56x slower
143+
144+
Rehearsal ---------------------------------------------
145+
celluloid 3.910000 0.540000 4.450000 ( 4.455316)
146+
async 2.730000 0.010000 2.740000 ( 2.736720)
147+
------------------------------------ total: 7.190000sec
148+
149+
user system total real
150+
celluloid 3.880000 0.550000 4.430000 ( 4.435163)
151+
async 2.740000 0.010000 2.750000 ( 2.750706)
152+
153+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154+
Short-lived objects
155+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156+
84157
Calculating -------------------------------------
85-
celluloid 26.000 i/100ms
86-
async 47.000 i/100ms
158+
future 19.000 i/100ms
159+
async 19.000 i/100ms
87160
-------------------------------------------------
88-
celluloid 279.9126.1%) i/s - 1.404k
89-
async 478.9322.1%) i/s - 2.397k
161+
future 191.7383.7%) i/s - 969.000
162+
async 188.0854.3%) i/s - 950.000
90163

91164
Comparison:
92-
async: 478.9 i/s
93-
celluloid: 279.9 i/s - 1.71x slower
165+
future: 191.7 i/s
166+
async: 188.1 i/s - 1.02x slower
94167

95168
Rehearsal ---------------------------------------------
96-
celluloid 4.080000 0.620000 4.700000 ( 4.695271)
97-
async 2.280000 0.100000 2.380000 ( 2.345327)
98-
------------------------------------ total: 7.080000sec
169+
celluloid 0.110000 0.020000 0.130000 ( 0.131996)
170+
async 0.040000 0.010000 0.050000 ( 0.037236)
171+
------------------------------------ total: 0.180000sec
99172

100173
user system total real
101-
celluloid 3.910000 0.580000 4.490000 ( 4.503884)
102-
async 2.220000 0.190000 2.410000 ( 2.340467)
174+
celluloid 0.160000 0.040000 0.200000 ( 0.186817)
175+
async 0.040000 0.010000 0.050000 ( 0.051579)
103176

104177
===========================================================
105-
jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 +jit [darwin-x86_64]
178+
jruby 9.0.1.0 (2.2.2) 2015-09-02 583f336 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64]
106179
===========================================================
107180

181+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182+
Long-lived objects
183+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184+
185+
Calculating -------------------------------------
186+
celluloid 1.000 i/100ms
187+
async 14.000 i/100ms
188+
-------------------------------------------------
189+
celluloid 139.631 (±42.3%) i/s - 473.000
190+
async 883.424 (±26.6%) i/s - 3.514k
191+
192+
Comparison:
193+
async: 883.4 i/s
194+
celluloid: 139.6 i/s - 6.33x slower
195+
196+
Rehearsal ---------------------------------------------
197+
celluloid 7.420000 1.930000 9.350000 ( 6.625224)
198+
async 2.630000 0.210000 2.840000 ( 1.574823)
199+
----------------------------------- total: 12.190000sec
200+
201+
user system total real
202+
celluloid 5.910000 1.720000 7.630000 ( 5.995677)
203+
async 2.610000 0.190000 2.800000 ( 1.594092)
204+
205+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206+
Short-lived objects
207+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208+
108209
Calculating -------------------------------------
109-
celluloid 2.000 i/100ms
110-
async 32.000 i/100ms
210+
future 40.000 i/100ms
211+
async 48.000 i/100ms
111212
-------------------------------------------------
112-
celluloid 72.88726.1%) i/s - 334.000
113-
async 1.822k (±31.6%) i/s - 6.368k
213+
future 640.057 4.8%) i/s - 3.200k
214+
async 570.240 (± 4.7%) i/s - 2.880k
114215

115216
Comparison:
116-
async: 1821.9 i/s
117-
celluloid: 72.9 i/s - 25.00x slower
217+
future: 640.1 i/s
218+
async: 570.2 i/s - 1.12x slower
118219

119220
Rehearsal ---------------------------------------------
120-
celluloid 8.890000 1.700000 10.590000 ( 5.930000)
121-
async 2.250000 0.150000 2.400000 ( 1.283000)
122-
----------------------------------- total: 12.990000sec
221+
celluloid 1.420000 0.090000 1.510000 ( 0.523106)
222+
async 0.020000 0.000000 0.020000 ( 0.006935)
223+
------------------------------------ total: 1.530000sec
123224

124225
user system total real
125-
celluloid 6.310000 1.530000 7.840000 ( 5.817000)
126-
async 1.590000 0.060000 1.650000 ( 0.912000)
226+
celluloid 0.620000 0.100000 0.720000 ( 0.293182)
227+
async 0.020000 0.000000 0.020000 ( 0.007434)

0 commit comments

Comments
 (0)