|
1 | 1 | #!/usr/bin/env ruby
|
2 | 2 |
|
3 |
| -$: << File.expand_path('../../lib', __FILE__) |
| 3 | +#$: << File.expand_path('../../lib', __FILE__) |
4 | 4 |
|
5 | 5 | require 'benchmark'
|
6 | 6 | require 'benchmark/ips'
|
|
10 | 10 |
|
11 | 11 | class CelluloidClass
|
12 | 12 | include Celluloid
|
13 |
| - def foo |
14 |
| - end |
15 |
| - def bar(latch) |
16 |
| - latch.count_down |
| 13 | + def foo(latch = nil) |
| 14 | + latch.count_down if latch |
17 | 15 | end
|
18 | 16 | end
|
19 | 17 |
|
20 | 18 | class AsyncClass
|
21 | 19 | include Concurrent::Async
|
22 |
| - def foo |
23 |
| - end |
24 |
| - def bar(latch) |
25 |
| - latch.count_down |
| 20 | + def foo(latch = nil) |
| 21 | + latch.count_down if latch |
26 | 22 | end
|
27 | 23 | end
|
28 | 24 |
|
29 | 25 | IPS_NUM = 100
|
30 | 26 | BMBM_NUM = 100_000
|
31 | 27 |
|
32 | 28 | Benchmark.ips do |bm|
|
33 |
| - latch = Concurrent::CountDownLatch.new(1) |
34 | 29 | celluloid = CelluloidClass.new
|
35 | 30 | bm.report('celluloid') do
|
36 |
| - IPS_NUM.times { celluloid.async.foo } |
37 |
| - celluloid.bar(latch) |
| 31 | + latch = Concurrent::CountDownLatch.new(IPS_NUM) |
| 32 | + IPS_NUM.times { celluloid.async.foo(latch) } |
38 | 33 | latch.wait
|
39 | 34 | end
|
40 | 35 |
|
41 | 36 | async = AsyncClass.new
|
42 |
| - latch = Concurrent::CountDownLatch.new(1) |
43 | 37 | bm.report('async') do
|
44 |
| - IPS_NUM.times { async.async.foo } |
45 |
| - async.bar(latch) |
| 38 | + latch = Concurrent::CountDownLatch.new(IPS_NUM) |
| 39 | + IPS_NUM.times { async.async.foo(latch) } |
46 | 40 | latch.wait
|
47 | 41 | end
|
48 | 42 |
|
49 | 43 | bm.compare!
|
50 | 44 | end
|
51 | 45 |
|
52 |
| -#Benchmark.bmbm do |bm| |
53 |
| - #bm.report('celluloid') do |
54 |
| - #end |
55 |
| - #bm.report('async') do |
56 |
| - #end |
57 |
| -#end |
| 46 | +Benchmark.bmbm do |bm| |
| 47 | + celluloid = CelluloidClass.new |
| 48 | + bm.report('celluloid') do |
| 49 | + latch = Concurrent::CountDownLatch.new(BMBM_NUM) |
| 50 | + BMBM_NUM.times { celluloid.async.foo(latch) } |
| 51 | + latch.wait |
| 52 | + end |
| 53 | + |
| 54 | + async = AsyncClass.new |
| 55 | + bm.report('async') do |
| 56 | + latch = Concurrent::CountDownLatch.new(BMBM_NUM) |
| 57 | + BMBM_NUM.times { async.async.foo(latch) } |
| 58 | + latch.wait |
| 59 | + end |
| 60 | +end |
| 61 | + |
| 62 | +__END__ |
| 63 | + |
| 64 | +=========================================================== |
| 65 | +Async Benchmarks |
| 66 | +=========================================================== |
| 67 | + |
| 68 | +Computer: |
| 69 | + |
| 70 | +* OS X Yosemite |
| 71 | + - Version 10.10.4 |
| 72 | +* MacBook Pro |
| 73 | + - Retina, 13-inch, Early 2015 |
| 74 | +* Processor 3.1 GHz Intel Core i7 |
| 75 | +* Memory 16 GB 1867 MHz DDR3 |
| 76 | +* Physical Volumes: |
| 77 | + - Apple SSD SM0512G |
| 78 | + - 500 GB |
| 79 | + |
| 80 | +=========================================================== |
| 81 | +ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] |
| 82 | +=========================================================== |
| 83 | + |
| 84 | +Calculating ------------------------------------- |
| 85 | + celluloid 26.000 i/100ms |
| 86 | + async 47.000 i/100ms |
| 87 | +------------------------------------------------- |
| 88 | + celluloid 279.912 (± 6.1%) i/s - 1.404k |
| 89 | + async 478.932 (± 2.1%) i/s - 2.397k |
| 90 | + |
| 91 | +Comparison: |
| 92 | + async: 478.9 i/s |
| 93 | + celluloid: 279.9 i/s - 1.71x slower |
| 94 | + |
| 95 | +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 |
| 99 | + |
| 100 | + user system total real |
| 101 | +celluloid 3.910000 0.580000 4.490000 ( 4.503884) |
| 102 | +async 2.220000 0.190000 2.410000 ( 2.340467) |
| 103 | + |
| 104 | +=========================================================== |
| 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] |
| 106 | +=========================================================== |
| 107 | + |
| 108 | +Calculating ------------------------------------- |
| 109 | + celluloid 2.000 i/100ms |
| 110 | + async 32.000 i/100ms |
| 111 | +------------------------------------------------- |
| 112 | + celluloid 72.887 (±26.1%) i/s - 334.000 |
| 113 | + async 1.822k (±31.6%) i/s - 6.368k |
| 114 | + |
| 115 | +Comparison: |
| 116 | + async: 1821.9 i/s |
| 117 | + celluloid: 72.9 i/s - 25.00x slower |
| 118 | + |
| 119 | +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 |
| 123 | + |
| 124 | + user system total real |
| 125 | +celluloid 6.310000 1.530000 7.840000 ( 5.817000) |
| 126 | +async 1.590000 0.060000 1.650000 ( 0.912000) |
0 commit comments