Last active
August 29, 2015 14:11
-
-
Save byroot/919e7756be7f89ec19af to your computer and use it in GitHub Desktop.
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
$ bundle exec ruby per_thread_registry_benchmark.rb | |
Calculating ------------------------------------- | |
thread-safe 25.176k i/100ms | |
thread-unsafe 30.069k i/100ms | |
------------------------------------------------- | |
thread-safe 1.480M (± 6.5%) i/s - 7.377M | |
thread-unsafe 2.480M (± 7.2%) i/s - 12.328M |
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
ruby per_thread_registry_benchmark.rb | |
Calculating ------------------------------------- | |
thread-safe 25.525k i/100ms | |
thread-unsafe 29.837k i/100ms | |
------------------------------------------------- | |
thread-safe 1.691M (± 7.5%) i/s - 8.398M | |
thread-unsafe 2.440M (± 7.8%) i/s - 12.114M |
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 'active_support/all' | |
require 'benchmark/ips' | |
class ThreadSafeRegistry | |
extend ActiveSupport::PerThreadRegistry | |
attr_accessor :foo | |
end | |
module GlobalRegistry | |
include ActiveSupport::PerThreadRegistry | |
private | |
def instance | |
@instance ||= new | |
end | |
def per_thread_registry_instance | |
@instance ||= new | |
end | |
end | |
class ThreadUnsafeRegistry | |
extend GlobalRegistry | |
attr_accessor :foo | |
end | |
ActiveSupport::PerThreadRegistry.send(:define_method, :instance, GlobalRegistry.instance_method(:instance)) | |
ActiveSupport::PerThreadRegistry.module_eval { private :instance } | |
Benchmark.ips do |x| | |
x.report('thread-safe') { ThreadSafeRegistry.foo } | |
x.report('thread-unsafe') { ThreadUnsafeRegistry.foo } | |
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
$ ruby monkey_patch.rb | |
Calculating ------------------------------------- | |
thread-safe 30.865k i/100ms | |
thread-unsafe 30.602k i/100ms | |
------------------------------------------------- | |
thread-safe 2.725M (± 7.8%) i/s - 13.519M | |
thread-unsafe 2.765M (± 7.3%) i/s - 13.740M |
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 'active_support/all' | |
require 'benchmark/ips' | |
class ThreadSafeRegistry | |
extend ActiveSupport::PerThreadRegistry | |
attr_accessor :foo | |
end | |
module GlobalRegistry | |
include ActiveSupport::PerThreadRegistry | |
private | |
def instance | |
@instance ||= new | |
end | |
def per_thread_registry_instance | |
@instance ||= new | |
end | |
end | |
class ThreadUnsafeRegistry | |
extend GlobalRegistry | |
attr_accessor :foo | |
end | |
Benchmark.ips do |x| | |
x.report('thread-safe') { ThreadSafeRegistry.foo } | |
x.report('thread-unsafe') { ThreadUnsafeRegistry.foo } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment