Sha256: e81d024f3b4b527219e4672a510df85a918df3078392fcd3f10642271bfe6be5
Contents?: true
Size: 1.41 KB
Versions: 10
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true # # This benchmark measures the efficiency of NamespaceCache. # # Run it multiple times with cache on/off to see the results: # # $ bundle exec ruby namespaced_lookup_cache.rb # $ bundle exec ruby namespaced_lookup_cache.rb # $ NO_CACHE=1 bundle exec ruby namespaced_lookup_cache.rb # $ NO_CACHE=1 bundle exec ruby namespaced_lookup_cache.rb # $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "action_policy" require "benchmark/ips" GC.disable class A; end class B; end module X class BPolicy < ActionPolicy::Base; end module Y module Z class APolicy < ActionPolicy::Base; end end end end a = A.new b = B.new if ENV["NO_CACHE"] ActionPolicy::LookupChain.namespace_cache_enabled = false end Benchmark.ips do |x| x.warmup = 0 x.report("cache A") do ActionPolicy.lookup(a, namespace: X::Y::Z) end x.report("cache B") do ActionPolicy.lookup(b, namespace: X::Y::Z) end x.report("no cache A") do ActionPolicy.lookup(a, namespace: X::Y::Z) end x.report("no cache B") do ActionPolicy.lookup(b, namespace: X::Y::Z) end x.hold! "temp_results" x.compare! end # # Comparison: # cache B: 178577.4 i/s # cache A: 173061.4 i/s - same-ish: difference falls within error # no cache A: 97991.7 i/s - same-ish: difference falls within error # no cache B: 42505.4 i/s - 4.20x slower
Version data entries
10 entries across 10 versions & 1 rubygems