1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
#!/usr/bin/env ruby
#$: << File.expand_path('../../lib', __FILE__)
require 'benchmark'
require 'benchmark/ips'
require 'concurrent'
require 'celluloid'
class CelluloidClass
include Celluloid
def foo(latch = nil)
latch.count_down if latch
end
end
class AsyncClass
include Concurrent::Async
def foo(latch = nil)
latch.count_down if latch
end
end
IPS_NUM = 100
BMBM_NUM = 100_000
SMALL_BMBM = 250
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts "Long-lived objects"
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts ""
Benchmark.ips do |bm|
celluloid = CelluloidClass.new
bm.report('celluloid') do
latch = Concurrent::CountDownLatch.new(IPS_NUM)
IPS_NUM.times { celluloid.async.foo(latch) }
latch.wait
end
async = AsyncClass.new
bm.report('async') do
latch = Concurrent::CountDownLatch.new(IPS_NUM)
IPS_NUM.times { async.async.foo(latch) }
latch.wait
end
bm.compare!
end
Benchmark.bmbm do |bm|
celluloid = CelluloidClass.new
bm.report('celluloid') do
latch = Concurrent::CountDownLatch.new(BMBM_NUM)
BMBM_NUM.times { celluloid.async.foo(latch) }
latch.wait
end
async = AsyncClass.new
bm.report('async') do
latch = Concurrent::CountDownLatch.new(BMBM_NUM)
BMBM_NUM.times { async.async.foo(latch) }
latch.wait
end
end
puts ""
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts "Short-lived objects"
puts "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts ""
Benchmark.ips do |bm|
bm.report('future') do
latch = Concurrent::CountDownLatch.new(IPS_NUM)
IPS_NUM.times do
Concurrent::Future.execute { latch.count_down }
end
latch.wait
end
async = AsyncClass.new
bm.report('async') do
latch = Concurrent::CountDownLatch.new(IPS_NUM)
IPS_NUM.times { AsyncClass.new.async.foo(latch) }
latch.wait
end
bm.compare!
end
Benchmark.bmbm do |bm|
bm.report('celluloid') do
latch = Concurrent::CountDownLatch.new(SMALL_BMBM)
SMALL_BMBM.times { CelluloidClass.new.async.foo(latch) }
latch.wait
end
bm.report('async') do
latch = Concurrent::CountDownLatch.new(SMALL_BMBM)
SMALL_BMBM.times { AsyncClass.new.async.foo(latch) }
latch.wait
end
end
__END__
===========================================================
Async Benchmarks
===========================================================
Computer:
* OS X Yosemite
- Version 10.10.4
* MacBook Pro
- Retina, 13-inch, Early 2015
* Processor 3.1 GHz Intel Core i7
* Memory 16 GB 1867 MHz DDR3
* Physical Volumes:
- Apple SSD SM0512G
- 500 GB
===========================================================
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
===========================================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Long-lived objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Calculating -------------------------------------
celluloid 22.000 i/100ms
async 37.000 i/100ms
-------------------------------------------------
celluloid 239.639 (±10.8%) i/s - 1.188k
async 374.885 (± 2.7%) i/s - 1.887k
Comparison:
async: 374.9 i/s
celluloid: 239.6 i/s - 1.56x slower
Rehearsal ---------------------------------------------
celluloid 3.910000 0.540000 4.450000 ( 4.455316)
async 2.730000 0.010000 2.740000 ( 2.736720)
------------------------------------ total: 7.190000sec
user system total real
celluloid 3.880000 0.550000 4.430000 ( 4.435163)
async 2.740000 0.010000 2.750000 ( 2.750706)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Short-lived objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Calculating -------------------------------------
future 19.000 i/100ms
async 19.000 i/100ms
-------------------------------------------------
future 191.738 (± 3.7%) i/s - 969.000
async 188.085 (± 4.3%) i/s - 950.000
Comparison:
future: 191.7 i/s
async: 188.1 i/s - 1.02x slower
Rehearsal ---------------------------------------------
celluloid 0.110000 0.020000 0.130000 ( 0.131996)
async 0.040000 0.010000 0.050000 ( 0.037236)
------------------------------------ total: 0.180000sec
user system total real
celluloid 0.160000 0.040000 0.200000 ( 0.186817)
async 0.040000 0.010000 0.050000 ( 0.051579)
===========================================================
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]
===========================================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Long-lived objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Calculating -------------------------------------
celluloid 1.000 i/100ms
async 14.000 i/100ms
-------------------------------------------------
celluloid 139.631 (±42.3%) i/s - 473.000
async 883.424 (±26.6%) i/s - 3.514k
Comparison:
async: 883.4 i/s
celluloid: 139.6 i/s - 6.33x slower
Rehearsal ---------------------------------------------
celluloid 7.420000 1.930000 9.350000 ( 6.625224)
async 2.630000 0.210000 2.840000 ( 1.574823)
----------------------------------- total: 12.190000sec
user system total real
celluloid 5.910000 1.720000 7.630000 ( 5.995677)
async 2.610000 0.190000 2.800000 ( 1.594092)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Short-lived objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Calculating -------------------------------------
future 40.000 i/100ms
async 48.000 i/100ms
-------------------------------------------------
future 640.057 (± 4.8%) i/s - 3.200k
async 570.240 (± 4.7%) i/s - 2.880k
Comparison:
future: 640.1 i/s
async: 570.2 i/s - 1.12x slower
Rehearsal ---------------------------------------------
celluloid 1.420000 0.090000 1.510000 ( 0.523106)
async 0.020000 0.000000 0.020000 ( 0.006935)
------------------------------------ total: 1.530000sec
user system total real
celluloid 0.620000 0.100000 0.720000 ( 0.293182)
async 0.020000 0.000000 0.020000 ( 0.007434)
|