Benchmark.measure { 50.times { Futureable1.p.async.get } }.real
# => 12.045974
Benchmark.measure { 50.times { Futureable2.p.async.get } }.real
# => 0.002454
This don't make nooo sense. In theory, it should be almost semantically equivalent, `Futurable1` making only one more access to `Celluloid::Actor[:Futurable1]`. The `||=` is essentially checking for `nil` before assigning. Why it's such a big difference, I'd love to know.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
require "celluloid" | |
class Futureable1 | |
include Celluloid | |
class << self | |
def p | |
if Celluloid::Actor[:Futureable1].nil? | |
Celluloid::Actor[:Futureable1] = Futureable1.pool(size: 2) | |
end | |
Celluloid::Actor[:Futureable1] | |
end | |
end | |
def get | |
sleep 0.5 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
require "celluloid" | |
class Futureable2 | |
include Celluloid | |
class << self | |
def p | |
Celluloid::Actor[:Futureable2] ||= Futureable2.pool(size: 2) | |
end | |
end | |
def get | |
sleep 0.5 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment