@@ -22,13 +22,6 @@ def foo(latch = nil)
22
22
end
23
23
end
24
24
25
- class AsyncAlternateClass
26
- include Concurrent ::AsyncAlternate
27
- def foo ( latch = nil )
28
- latch . count_down if latch
29
- end
30
- end
31
-
32
25
IPS_NUM = 100
33
26
BMBM_NUM = 100_000
34
27
SMALL_BMBM = 250
@@ -47,14 +40,7 @@ def foo(latch = nil)
47
40
end
48
41
49
42
async = AsyncClass . new
50
- bm . report ( 'async, thread per object' ) do
51
- latch = Concurrent ::CountDownLatch . new ( IPS_NUM )
52
- IPS_NUM . times { async . async . foo ( latch ) }
53
- latch . wait
54
- end
55
-
56
- async = AsyncAlternateClass . new
57
- bm . report ( 'async, global thread pool' ) do
43
+ bm . report ( 'async' ) do
58
44
latch = Concurrent ::CountDownLatch . new ( IPS_NUM )
59
45
IPS_NUM . times { async . async . foo ( latch ) }
60
46
latch . wait
@@ -72,14 +58,7 @@ def foo(latch = nil)
72
58
end
73
59
74
60
async = AsyncClass . new
75
- bm . report ( 'async, thread per object' ) do
76
- latch = Concurrent ::CountDownLatch . new ( BMBM_NUM )
77
- BMBM_NUM . times { async . async . foo ( latch ) }
78
- latch . wait
79
- end
80
-
81
- async = AsyncAlternateClass . new
82
- bm . report ( 'async, global thread pool' ) do
61
+ bm . report ( 'async' ) do
83
62
latch = Concurrent ::CountDownLatch . new ( BMBM_NUM )
84
63
BMBM_NUM . times { async . async . foo ( latch ) }
85
64
latch . wait
@@ -92,16 +71,35 @@ def foo(latch = nil)
92
71
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
93
72
puts ""
94
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
+
95
93
Benchmark . bmbm do |bm |
96
94
bm . report ( 'celluloid' ) do
97
95
latch = Concurrent ::CountDownLatch . new ( SMALL_BMBM )
98
96
SMALL_BMBM . times { CelluloidClass . new . async . foo ( latch ) }
99
97
latch . wait
100
98
end
101
99
102
- bm . report ( 'async, global thread pool ' ) do
100
+ bm . report ( 'async' ) do
103
101
latch = Concurrent ::CountDownLatch . new ( SMALL_BMBM )
104
- SMALL_BMBM . times { AsyncAlternateClass . new . async . foo ( latch ) }
102
+ SMALL_BMBM . times { AsyncClass . new . async . foo ( latch ) }
105
103
latch . wait
106
104
end
107
105
end
@@ -133,46 +131,37 @@ def foo(latch = nil)
133
131
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134
132
135
133
Calculating -------------------------------------
136
- celluloid 24.000 i/100ms
137
- async, thread per object
138
- 36.000 i/100ms
139
- async, global thread pool
140
- 36.000 i/100ms
134
+ celluloid 21.000 i/100ms
135
+ async 36.000 i/100ms
141
136
-------------------------------------------------
142
- celluloid 270.238 (±10.4%) i/s - 1.344k
143
- async, thread per object
144
- 366.529 (± 3.3%) i/s - 1.836k
145
- async, global thread pool
146
- 365.264 (± 3.0%) i/s - 1.836k
137
+ celluloid 218.207 (±17.0%) i/s - 1.071k
138
+ async 375.318 (± 3.2%) i/s - 1.908k
147
139
148
140
Comparison:
149
- async, thread per object: 366.5 i/s
150
- async, global thread pool: 365.3 i/s - 1.00x slower
151
- celluloid: 270.2 i/s - 1.36x slower
141
+ async: 375.3 i/s
142
+ celluloid: 218.2 i/s - 1.72x slower
152
143
153
- Rehearsal -------------------------------------------------------------
154
- celluloid 4.110000 0.670000 4.780000 ( 4.784982)
155
- async, thread per object 3.050000 0.090000 3.140000 ( 3.128709)
156
- async, global thread pool 2.960000 0.020000 2.980000 ( 2.981984)
157
- --------------------------------------------------- total: 10.900000sec
144
+ Rehearsal ---------------------------------------------
145
+ celluloid 4.150000 0.690000 4.840000 ( 4.826509)
146
+ async 2.740000 0.010000 2.750000 ( 2.762197)
147
+ ------------------------------------ total: 7.590000sec
158
148
159
- user system total real
160
- celluloid 4.220000 0.700000 4.920000 ( 4.955064)
161
- async, thread per object 3.000000 0.060000 3.060000 ( 3.055045)
162
- async, global thread pool 3.150000 0.060000 3.210000 ( 3.240574)
149
+ user system total real
150
+ celluloid 4.060000 0.680000 4.740000 ( 4.734005)
151
+ async 2.720000 0.040000 2.760000 ( 2.745365)
163
152
164
153
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165
154
Short-lived objects
166
155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167
156
168
- Rehearsal -------------------------------------------------------------
169
- celluloid 0.180000 0.050000 0.230000 ( 0.220111 )
170
- async, global thread pool 0.090000 0.020000 0.110000 ( 0.111569 )
171
- ---------------------------------------------------- total: 0.340000sec
157
+ Rehearsal ---------------------------------------------
158
+ celluloid 0.120000 0.030000 0.150000 ( 0.146426 )
159
+ async 0.080000 0.020000 0.100000 ( 0.091462 )
160
+ ------------------------------------ total: 0.250000sec
172
161
173
- user system total real
174
- celluloid 0.240000 0.120000 0.360000 ( 0.350697 )
175
- async, global thread pool 0.010000 0.000000 0.010000 ( 0.013509 )
162
+ user system total real
163
+ celluloid 0.160000 0.060000 0.220000 ( 0.216363 )
164
+ async 0.010000 0.010000 0.020000 ( 0.015761 )
176
165
177
166
===========================================================
178
167
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]
@@ -184,42 +173,33 @@ def foo(latch = nil)
184
173
185
174
Calculating -------------------------------------
186
175
celluloid 2.000 i/100ms
187
- async, thread per object
188
- 24.000 i/100ms
189
- async, global thread pool
190
- 48.000 i/100ms
176
+ async 20.000 i/100ms
191
177
-------------------------------------------------
192
- celluloid 130.115 (±40.7%) i/s - 492.000
193
- async, thread per object
194
- 896.257 (±17.6%) i/s - 3.984k
195
- async, global thread pool
196
- 926.262 (±11.0%) i/s - 4.560k
178
+ celluloid 141.910 (±40.9%) i/s - 508.000
179
+ async 783.468 (±32.4%) i/s - 3.120k
197
180
198
181
Comparison:
199
- async, global thread pool: 926.3 i/s
200
- async, thread per object: 896.3 i/s - 1.03x slower
201
- celluloid: 130.1 i/s - 7.12x slower
182
+ async: 783.5 i/s
183
+ celluloid: 141.9 i/s - 5.52x slower
202
184
203
- Rehearsal -------------------------------------------------------------
204
- celluloid 5.800000 1.590000 7.390000 ( 5.306000)
205
- async, thread per object 2.880000 0.190000 3.070000 ( 1.601000)
206
- async, global thread pool 2.150000 0.130000 2.280000 ( 1.172000)
207
- --------------------------------------------------- total: 12.740000sec
185
+ Rehearsal ---------------------------------------------
186
+ celluloid 5.880000 1.560000 7.440000 ( 5.464000)
187
+ async 2.800000 0.230000 3.030000 ( 1.615000)
188
+ ----------------------------------- total: 10.470000sec
208
189
209
- user system total real
210
- celluloid 5.590000 1.520000 7.110000 ( 5.391000)
211
- async, thread per object 2.480000 0.160000 2.640000 ( 1.364000)
212
- async, global thread pool 1.850000 0.130000 1.980000 ( 1.008000)
190
+ user system total real
191
+ celluloid 5.660000 1.500000 7.160000 ( 5.432000)
192
+ async 3.040000 0.250000 3.290000 ( 1.749000)
213
193
214
194
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215
195
Short-lived objects
216
196
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
197
218
- Rehearsal -------------------------------------------------------------
219
- celluloid 1.530000 0.140000 1.670000 ( 0.597000 )
220
- async, global thread pool 0.060000 0.000000 0.060000 ( 0.018000)
221
- ---------------------------------------------------- total: 1.730000sec
198
+ Rehearsal ---------------------------------------------
199
+ celluloid 1.580000 0.120000 1.700000 ( 0.612000 )
200
+ async 0.060000 0.010000 0.070000 ( 0.018000)
201
+ ------------------------------------ total: 1.770000sec
222
202
223
- user system total real
224
- celluloid 1.160000 0.160000 1.320000 ( 0.431000 )
225
- async, global thread pool 0.020000 0.000000 0.020000 ( 0.009000)
203
+ user system total real
204
+ celluloid 0.670000 0.110000 0.780000 ( 0.295000 )
205
+ async 0.030000 0.000000 0.030000 ( 0.009000)
0 commit comments